简体   繁体   English

用于html输入元素的name属性的数组长度

[英]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.

相关问题 如何将angularjs变量值赋给html元素属性,例如输入elememnt的name属性 - How to assign angularjs variable value to html element attribute, such as input elememnt's name attribute 如何将knockout的Observable数组长度绑定到html元素 - how to bind knockout's Observable array length to an html element jQuery:对于input元素的每个属性,我如何获得该输入元素的名称? - jQuery: For each attribute of an input element how do I get that input element's name? 带有JavaScript的HTML表单输入标记名称元素数组 - HTML form input tag name element array with JavaScript 模式属性不能在输入元素中使用 - Pattern attribute can't be used in input element 使用数组命名HTML中的输入字段时 - 如何计算数组长度? - When using array to name input fields in HTML — how to count array length? 如何使用 select 和 HTML 元素 jQuery 或 Z686155AF75A60A0F6E9D80C1F7EDD3E 元素的名称和名称 - How to select an HTML element using jQuery or JavaScript and the element's name attribute 使用for循环,数组和eventListener更改输入元素的“名称”属性-无jQuery - Change “name” attribute of input element using for-loop, array, and eventListener - No jQuery 如何获取一个对象的“值”属性<input> html中的元素? - How to acquire the "value" attribute of an <input> element in html? 获取 HTML 元素的名称属性并将其发送到服务器 - Getting the name attribute of an HTML element and sending it to the server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM