如何将表单django添加到jquery函数?

时间:2016-05-13 06:46:31

标签: javascript jquery django

如何将表单django添加到jQuery命令?我的表里面有一个按钮,当用户点击按钮时会插入新行。在列Product中,有一个来自数据库的组合框加载,供用户选择Product。但是我有一些问题

  

Uncaught SyntaxError:意外的令牌类

代码:

<script>
    var rowIndex = 0;
    $("#addrow").on('click', function () {
        rowIndex++;

        var newRow = '<tr><td>'{{ item_info.item }}'</td>' +
                '<td><input id="Quantity' + rowIndex + '" name="Quantity' + rowIndex + '" type="text" /></td>"' +
                '<td><input id="Price' + rowIndex + '" name="Price' + rowIndex + '" type="text" /></td>"' +
                '<td><input id="Amount' + rowIndex + '" name="Amount' + rowIndex + '" type="text" /></td>"' +
                '<td><button type="button" class="removerow btn btn-white fa fa-minus" id="removerow' + rowIndex + '" name="removerow' + rowIndex + '" value="Remove">' +
                '</button></td></tr>';

        if ($("#dynamic-table > tbody > tr").is("*"))
            $("#dynamic-table > tbody > tr:last").after(newRow)
        else $("#dynamic-table > tbody").append(newRow)

    });

    $(document).on('click', "[class^=removerow]", function () {

        $(this).parents("tr").remove();
    });
</script>

当我在浏览器中查看时,它会显示错误

  

Uncaught SyntaxError:意外的令牌类。

错误在这里:

var newRow = '<tr><td>' <select class="form-control" id="id_item" name="item"> --red error in here
  <option value="" selected="selected">---Select Item---</option>
  <option value="1">iPhone 5S</option>
  <option value="2">iPhone 6S</option>
  <option value="3">iPhone 4S</option>
  <option value="4">iPhone 4</option>
  <option value="5">Galaxy S7</option>
  <option value="6">Galaxy S7 Edge</option>
  <option value="7">Galaxy S6</option>
  </select> '</td>' +
                '<td><input id="Quantity' + rowIndex + '" name="Quantity' +            rowIndex + '" type="text" /></td>"' +
                '<td><input id="Price' + rowIndex + '" name="Price' + rowIndex + '" type="text" /></td>"' +
                '<td><input id="Amount' + rowIndex + '" name="Amount' + rowIndex + '" type="text" /></td>"' +
                '<td><button type="button" class="removerow btn btn-white fa fa-minus" id="removerow' + rowIndex + '" name="removerow' + rowIndex + '" value="Remove">' +
                '</button></td></tr>';

0 个答案:

没有答案