[英]length of array used for html input element's name attribute
This bit of code below appends a div to another div. 下面的这段代码将div附加到另一个div。 The former div contains an input element with the name attribute "inputName[]".
前一个div包含一个具有名称属性“ inputName []”的输入元素。 I'm guessing this is an array that auto-increments as more divs are added.
我猜这是一个数组,它会随着添加更多的div而自动递增。 How can I output the length of this array?
如何输出此数组的长度? I tried to console.log it (as below), but it's not working.
我试图用console.log记录它(如下所示),但是它不起作用。
The error I get is "Uncaught TypeError: Cannot read property 'length' of undefined" 我得到的错误是“未捕获的TypeError:无法读取未定义的属性'length'”
What can I do to fix this please? 请问该如何解决?
$("#buttonid4").on("click", function() {
var string1 = "<div class='eight columns'>
<input type='text' size='76' placeholder='paste URL here' name='inputName[]'> </div>";
$("#deleteandadd").append(string1);
console.log(inputName.length);
});
if you want number of inputs with name "inputName[]" ,you can use name selecter in jquery. 如果要输入名称为“ inputName []”的输入,则可以在jquery中使用名称选择器。
like the following 像下面
$('#deleteandadd input[name="inputName[]"]').length
or 要么
var inputName= $('#deleteandadd input[name="inputName[]"]')
console.log(inputName.length)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.