2014-11-25 125 views
0

我对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"; 

    ..... 



    }); 
+0

是否推迟'var a = document.getElementById('bookingform');'直到DOM准备好之后?你的控制台是否有错误? – 2014-11-25 04:56:22

+0

它在$(document).ready(function()中调用,是的,我在控制台中得到的错误是Uncaught TypeError:无法读取null的属性'style' - page1(通常工作的)和预订我得到:Uncaught TypeError:无法读取null的属性'样式'@BenHarold – baao 2014-11-25 05:00:41

+2

这就是为什么你的JavaScript不工作。你可以添加你的JavaScript代码。这个错误意味着你引用了一个不存在的元素btw – 2014-11-25 05:03:40

回答

0

看起来你从来没有加入该ID的形式本身。您正尝试访问不存在的内容。

Form::open(array('url' => 'bookings', 'class' => 'form-inline', 'role' => 'form', 'id'=>'bookingForm')