我使用下面的代碼的HTML表單: <input type="text" name="cars[]" required>
'如何獲得HTML的輸入在JavaScript
注意使用‘汽車[]’的名稱。
這使我可以有多個具有相同名稱的輸入。
我想從javascript中獲得所有輸入的答案。
有人可以澄清如何做到這一點?
我對這個以下錯誤的代碼:
var element = document.getInput("cars[]");
for(i=0; i<element.length;i++){
alert(element[i].value);
}
請更正上面的代碼或提及另一種解決方案
感謝
getElementsByName或querySelectorAll ... – epascarello
document.getElementsByName( 「汽車[]」)? –
你有什麼JavaScript代碼/? – putvande