Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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 无法将值填充到<;输入>;使用jquery_Javascript_Jquery_Html - Fatal编程技术网

Javascript 无法将值填充到<;输入>;使用jquery

Javascript 无法将值填充到<;输入>;使用jquery,javascript,jquery,html,Javascript,Jquery,Html,我有这个html 类别 描述 行动 试试这个 $("input#categories\\["+lastrow+"\\]").val("111"); $("input#description\\["+lastrow+"\\]").val("222"); Html代码 <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">&

我有这个html


类别
描述
行动
试试这个

$("input#categories\\["+lastrow+"\\]").val("111");

$("input#description\\["+lastrow+"\\]").val("222");
Html代码

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>


$(document).ready(function () {
    $('#bSimpanItem').click(function () {
        var iIndex = 0;  
        $('#tabel-item-borrowed tbody tr').each(function (index) {
            iIndex = index + 1
            $(this).find("td:eq(0)").find('#categories\\[' + iIndex + '\\]').val('111');
            $(this).find("td:eq(1)").find('#description\\[' + iIndex + '\\]').val('22');
        });
    });
});
</script>
</head>

<body style="width:50%;">
    <input type="button" value="bSimpanItem" id="bSimpanItem"/>
  <table id="tabel-item-borrowed" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th class="headtabel">Categories</th>
<th class="headtabel">Description</th>
<th class="headtabel">Action</th>
</tr>
</thead>
<tbody>
<tr id="t11">
<td>
<input id="categories[1]" type="text" name="categories1" size="40">
</td>
<td>
<input id="description[1]" type="text" name="description1" size="40">
</td>
<td>
<input id="delete[1]" type="button" name="delete" value="delete" size="5">
</td>
</tr>
<tr id="t12">
<td>
<input id="categories[2]" type="text" name="categories2" size="40">
</td>
<td>
<input id="description[2]" type="text" name="description2" size="40">
</td>
<td>
<input id="delete[2]" type="button" name="delete" value="delete" size="5">
</td>
</tr>
</tbody>
</table>
</body>

</html>

$(文档).ready(函数(){
$('#bSimpanItem')。单击(函数(){
var iIndex=0;
$('#tabel item to tbody tr')。每个(函数(索引){
指数=指数+1
$(this.find(“td:eq(0)”).find(“#categories\\['+iIndex+'\\]')).val('111');
$(this.find(“td:eq(1)”).find('description\\['+iIndex+'\\]')).val('22');
});
});
});
类别
描述
行动

您可以访问循环内的输入,如下所示:

$('input[id="categories[' + lastrow + ']"]').val("111");

[xxxx]
是一个属性选择器。如果id的值中包含它们,则需要按照中的说明对其进行转义

$("input#categories\\["+lastrow+"\\]");