【问题标题】:Trying to add input field when a click happens but gets missing argument list尝试在单击时添加输入字段但缺少参数列表
【发布时间】:2015-09-06 09:36:50
【问题描述】:

我正在尝试使用 laravel 的表单帮助程序添加输入字段,当我点击一个元素时,我正在这样做

    $('#segment-create').click(function(e){
        $('#segments').append("<div class='clearfix'> <div class='selectbox boxed pull-left'> {{ Form::selectopt('contact_property[]', [ 'class' => 'form-control pull-left', 'rel' => 'noresize' ], [ 'User Activity' => [ 'Clicked in the last' => 'clicked_last', 'Opened in the last' => 'opened_last', 'Not clicked in the last' => 'not_clicked_last', 'Not opened in the last' => 'not_opened_last' ], 'User Property' => [ 'City' => 'city', 'Age' => 'opened_last', 'Name' => 'name' ] ] ) }} <span class='pull-left' style=' width:50px; text-align:center; line-height:34px;'>is</span> <div class='selectbox boxed pull-left'> {{ Form::select('operator[]', array('0' => '=', '1' => '>', '2' => '≥', '3' => '<', '4' => '≤', '5' => '<>' ), null, ['class' => 'operator form-control pull-left']); }} <span class='pull-left' style=' width:50px; text-align:center; line-height:35px;'>to</span> <div class='pull-left'> {{ Form::text('value[]', null, ['class' => 'filter-name form-control', 'placeholder' => 'Filter value']) }} </div> <div class='pull-left'><a href='#' class='right cbx-filter cbx cbx-checked filter-checkbox'>&nbsp;</a> </div> </div> </div> </div>");
        e.preventDefault();
        // to check as complete todo list
        shoot({segment_name:$('#new-segment-name').val()}, 'POST');

    });

我不确定我在这里做错了什么,但我在 firebug 控制台中收到此错误

【问题讨论】:

    标签: javascript php jquery laravel-4


    【解决方案1】:

    对我来说,在 javascript 中附加过多的 HTML 代码并不是一个好主意。 作为解决方案,我建议创建一个新的刀片文件,如果需要,您将对其进行渲染,然后附加渲染文件。

    $('#segment-create').click(function(e){
        $.get('/url-to-remder-html', function(answ) {
            $('#segments').append(answ);
        });
        e.preventDefault();
        // to check as complete todo list
        shoot({segment_name:$('#new-segment-name').val()}, 'POST');
    

    });

    或者只是尝试在该部分代码上使用常规 HTML。

    【讨论】:

    • 不会只是增加http请求吗?
    • 在您的情况下,这是最好的解决方案。或者您可以将您的 html 代码隐藏起来,然后在玩具需要时获取并附加。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-16
    • 2022-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-06
    • 1970-01-01
    相关资源
    最近更新 更多