문제

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?

도움이 되었습니까?

해결책

var 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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top