Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel&jQuery-使用模板动态添加表单字段_Php_Jquery_Laravel 5 - Fatal编程技术网

Php Laravel&jQuery-使用模板动态添加表单字段

Php Laravel&jQuery-使用模板动态添加表单字段,php,jquery,laravel-5,Php,Jquery,Laravel 5,我使用的是Laravel,我有一个与服务有一对多关系的预订模型。因此,预订可以提供多种服务 {{ Form::open(array('url' => 'bookings')) }} <div class="panel panel-default"> <div class="panel-heading"><h3 class="panel-title">Services</h3></div>

我使用的是Laravel,我有一个与服务有一对多关系的预订模型。因此,预订可以提供多种服务

{{ Form::open(array('url' => 'bookings')) }}


    <div class="panel panel-default">
        <div class="panel-heading"><h3 class="panel-title">Services</h3></div>  
        <div class="panel-body" id="newServices">                 
            <a href="#" id="addService" class="btn btn-default pull-right">Add Service</a>
        </div>
    </div>

    {{ Form::submit('Create Booking', array('class' => 'btn btn-primary btn-vostra')) }}

{{ Form::close() }}
我已经建立了模型中的所有关系,并且工作正常

在我的预订创建视图文件中,我有一个面板,允许用户动态添加服务

{{ Form::open(array('url' => 'bookings')) }}


    <div class="panel panel-default">
        <div class="panel-heading"><h3 class="panel-title">Services</h3></div>  
        <div class="panel-body" id="newServices">                 
            <a href="#" id="addService" class="btn btn-default pull-right">Add Service</a>
        </div>
    </div>

    {{ Form::submit('Create Booking', array('class' => 'btn btn-primary btn-vostra')) }}

{{ Form::close() }}
我的问题是如何将“服务”视图模板文件动态添加到“预订”视图文件中

以下是我目前掌握的但不完整的信息:

$('#addService').click(function(e) {
        e.preventDefault();
        var html = {};
        $('#newServices').append(html);
});

如果有人仍在积极寻找答案,首先, 只需将js代码放在laravel页面的底部,就在@endsection之前。 但请确保您还编写了对app.js的引用,因为您需要它将javascript添加到页面和jquery中

下面是它的外观

@扩展“layouts.app” @“内容”一节 {{Form::label'customer_name','customer name'} {{Form::text'customer\u name',Input::old'customer\u name',array'class'=>'Form control'} {{Form::label'customer_address_line_1','address line 1'} {Form::text'customer_address_line_1',Input::old'customer_address_line_1',array'class'=>'Form control'} {{Form::label'customer_address_line_2','address line 2'} {Form::text'customer_address_line_2',Input::old'customer_address_line_2',array'class'=>'Form control'} {{asset'js/app.js'}} $document.readyfunction{ $'addService'。单击函数E{ e、 防止违约; var html={}; $'newServices'.appendhtml; }; };
@你怎么想出来的?你能分享一下解决方案吗?