拉拉维尔 4 个不同的页面@section正在破坏脚本

Laravel 4 different pages @section are breaking scripts

本文关键字:@section 脚本      更新时间:2023-09-26

我对 laravel 4 很陌生,正在尝试用另一个视图扩展我的布局。

我的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函数都运行没有任何问题,尽管它们只包含在layout.blade中.php


现在我创建了另一个视图,称为"bookings"及其相应的文件"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');

在MyScript.js中,JavaScript也中断了Page1.blade.php的内容。(并且在bookings.blade中不起作用.php)

我的路由.php文件如下:

Route::get('/', function()
{
    return View::make('page1');
});
Route::get('index', function() {
    return View::make('page1');
});

Route::get('bookings', 'BookingController@getBooking');
Route::post('bookings','BookingController@getBookingDates');

预订控制器

class BookingController extends BaseController {

    public function getBooking(){
        return View::make('bookings');
    }

    public function getBookingDates()
    {

        $data = Input::all();

        return View::make('bookings');
    }
}

关于拉拉维尔,我有什么完全不明白的,还是有人看到了问题?

编辑:

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";
    .....

    });

看起来您从未将该 ID 添加到表单本身。您正在尝试访问不存在的内容。

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