我對laravel 4非常陌生,並且試圖用另一種視圖來擴展我的佈局。Laravel 4個不同的頁面@section正在破解腳本
我有這個在我的layout.blade.php結束:
{{ HTML::script('js/jquery.nicescroll.min.js') }}
{{ HTML::script('js/jquery.pickmeup.min.js') }}
{{ HTML::script('js/myscript.js') }}
</body>
</html>
然後我有,我有頗多文件page1.blade.php,只顯示要領:
@extends('layout/layout')
@section('contents')
<section id="start">
......
</section>
@stop
在這個文件中,從myscript.js所有的JavaScript函數爲R unning沒有任何問題,但他們僅包含於layout.blade.php
現在我創造了另一種觀點認爲,所謂的「預約」,其對應的文件「bookings.blade.php」
這裏bookings.blade.php:
@extends('layout/layout')
@section('contents')
<section id="bookingform">
<div id="bookingforma" style="background-color: #00a651; height: 10px; width:100%;">
{{ Form::open(array('url' => 'bookings', 'class' => 'form-inline', 'role' => 'form')) }}
<div class="form-group">
<span><strong>Date available? </strong> </span>
{{ Form::text('from1',Input::get('from'),array('class' => 'form-control', 'id' => 'fromforma')) }}
</div> <span><strong> - </strong></span>
<div class="form-group">
{{ Form::text('to1',Input::get('to'),array('class' => 'form-control', 'id' => 'toforma')) }}
</div> <span><strong> for </strong></span>
<div class="checkbox">
{{ Form::select('persons1', array('1' => '1','2'=>'2','3'=>'3','4'=>'4'),Input::get('persons'),array('class' => 'form-control')) }}
</div>
{{ Form::submit('Request!', array('class' => 'btn btn-success')) }}
{{ Form::close() }}
</div>
</section>
@stop
基本上我做的正是與@section和@stop和@extends一樣page1.blade.php,但我不能使用任何的javascript函數。
確切的說,如果我叫一個
var a = document.getElementById('bookingform');
withing myscript.js,爲page1.blade.php內容的JavaScript休息了。 (而不是在bookings.blade.php工作)
我routes.php文件文件如下:
Route::get('/', function()
{
return View::make('page1');
});
Route::get('index', function() {
return View::make('page1');
});
Route::get('bookings', '[email protected]');
Route::post('bookings','[email protected]');
而且BookingController:
class BookingController extends BaseController {
public function getBooking(){
return View::make('bookings');
}
public function getBookingDates()
{
$data = Input::all();
return View::make('bookings');
}
}
有我完全沒有得到關於laravel的東西,還是有人看到這個問題?
編輯:
的javascript:
$(document).ready(function() {
function heightsetter() {
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
y = w.innerHeight || e.clientHeight || g.clientHeight;
return y;
}
var resizeTimeout;
window.onresize = function() {
clearTimeout(resizeTimeout);
var height = document.getElementById('start');
height.style.height = heightsetter() + "px";
var heightz = document.getElementById('hotels');
heightz.style.height = heightsetter() + "px";
var heightd = document.getElementById('training');
heightd.style.height = heightsetter() + "px";
resizeTimeout = setTimeout(function() {
}, 250);
};
var height = document.getElementById('start');
height.style.height = heightsetter() + "px";
var heightz = document.getElementById('hotels');
heightz.style.height = heightsetter() + "px";
var heightd = document.getElementById('training');
heightd.style.height = heightsetter() + "px";
var heightb = document.getElementById('bookingform'); //<<< **this breaks it**
heightb.style.height = heightsetter() + "px";
.....
});
是否推遲'var a = document.getElementById('bookingform');'直到DOM準備好之後?你的控制檯是否有錯誤? – 2014-11-25 04:56:22
它在$(document).ready(function()中調用,是的,我在控制檯中得到的錯誤是Uncaught TypeError:無法讀取null的屬性'style' - page1(通常工作的)和預訂我得到:Uncaught TypeError:無法讀取null的屬性'樣式'@BenHarold – baao 2014-11-25 05:00:41
這就是爲什麼你的JavaScript不工作。你可以添加你的JavaScript代碼。這個錯誤意味着你引用了一個不存在的元素btw – 2014-11-25 05:03:40