Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.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
Javascript 在ASP.NET核心MVC中使用jQuery动态生成HTML控件并更改ID属性_Javascript_Jquery_Asp.net Mvc_.net Core - Fatal编程技术网

Javascript 在ASP.NET核心MVC中使用jQuery动态生成HTML控件并更改ID属性

Javascript 在ASP.NET核心MVC中使用jQuery动态生成HTML控件并更改ID属性,javascript,jquery,asp.net-mvc,.net-core,Javascript,Jquery,Asp.net Mvc,.net Core,我正在.NET Core MVC中创建订单项表单。在我的表单中有一个添加按钮。单击add按钮后,将生成带有一些html控件的表格行。我的表格的html如下: <div class="card"> <div class="card-title"><h4>Order Information</h4></div> <div class="card-body">

我正在.NET Core MVC中创建订单项表单。在我的表单中有一个添加按钮。单击add按钮后,将生成带有一些html控件的表格行。我的表格的html如下:

<div class="card">
            <div class="card-title"><h4>Order Information</h4></div>
            <div class="card-body">
                <table id="mytable" class="table">
                    <thead>
                        <tr>
                            <th>Item Name</th>
                            <th>Serial No</th>
                            <th>Quantity</th>
                            <th>Unit Price</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="extraPerson">
                            <td>
                                <select asp-for="OrderDtls[0].ItemName" class="form-control selItem"></select>
                            </td>
                            <td>
                                <input asp-for="OrderDtls[0].SerialNo" type="text" class="form-control" />
                            </td>
                            <td>
                                <input asp-for="OrderDtls[0].Quantity" type="number" class="form-control" />
                            </td>
                            <td>
                                <input asp-for="OrderDtls[0].Price" type="number" class="form-control" />
                            </td>
                            <td>
                                <a href="#" id="add">
                                    <i class="fa fa-plus" aria-hidden="true"></i>
                                </a>

                                <a href="#">
                                    <i class="fa fa-minus" aria-hidden="true"></i>
                                </a>
                            </td>
                        </tr>                            
                    </tbody>
                </table>
            </div>
        </div>
$(document).ready(function () {
        $("#add").click(function () {
            var html = $('#mytable tbody>tr:first').clone(true);            
            html.find('[class=selItem]').attr("id", "newIds");
            html.insertAfter('#mytable tbody>tr:last');

            return false;
        });
    });
现在在这个代码中

html.find('[class=selItem]').attr(“id”,“newid”)


我想用一个新的ID属性来更改ID属性。但这并没有发生。有人能给我建议怎么做吗?

您使用了错误的类选择器,从

html.find('[class=selItem]').attr("id", "newIds");

$(文档).ready(函数(){
$(“#添加”)。单击(函数(){
var html=$('#mytable tbody>tr:first').clone(true);
html.find(“.selItem”).attr(“id”,“newid”);
html.insertAfter('#mytable tbody>tr:last');
返回false;
});
});

订单信息
项目名称
序列号
量
单价
试验

您使用了错误的类选择器,请从

html.find('[class=selItem]').attr("id", "newIds");

$(文档).ready(函数(){
$(“#添加”)。单击(函数(){
var html=$('#mytable tbody>tr:first').clone(true);
html.find(“.selItem”).attr(“id”,“newid”);
html.insertAfter('#mytable tbody>tr:last');
返回false;
});
});

订单信息
项目名称
序列号
量
单价
试验