admin管理员组文章数量:1289602
I have a <div id="inputform">
and in that div
there are multiple <input type="text">
.
How can I count the number of <input>
fields?
I have a <div id="inputform">
and in that div
there are multiple <input type="text">
.
How can I count the number of <input>
fields?
3 Answers
Reset to default 8var inputFormDiv = document.getElementById('inputForm');
alert(inputFormDiv.getElementsByTagName('input').length);
Using jQuery you would be able to count the number of elements of a certain type, class, etc. using the following line of JavaScript
$("div#inputForm input").length
If you're not using jQuery, take a look at Brian's answer, it should do what you need it to.
$('#inputform input[type="text"]').length;
本文标签: htmlJavaScript Count inputfields in a DivStack Overflow
版权声明:本文标题:html - JavaScript: Count inputfields in a Div - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741470454a2380571.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论