我有我的第10頁的輸入框變..獲取的getElementById從使用JavaScript
<input type="text" id="box1">
<input type="text" id="box2">
<input type="text" id="box3">
<input type="text" id="box4">
<input type="text" id="box5">
<input type="text" id="box6">
<input type="text" id="box7">
<input type="text" id="box8">
<input type="text" id="box9">
<input type="text" id="box10">
使用JavaScript我希望能夠選擇每個輸入,但僅應要求使用JavaScript。
我用下面的代碼:
document.getElementById("box1").value
其返回值(我想)
但是我希望能夠做一些事情有那麼請求,那麼下一個項目做一些事情與..
所以我創建了一個虛擬變量(把我的功能之外,因爲我不希望值回每個函數被調用時重置爲1:
var current_item = "1";
然後我希望能夠選擇使用此變量的項目,我已經用它喜歡:
document.getElementById("box" + current_item).value
current_item = current_item + 1;
但它不工作。 如果我警告current_item變量,它將返回undefined。
如果我的current_item變量添加到我的功能,它的工作原理和做什麼,我想要它做的,而是不斷重新回到1(作爲功能重建的變量)。
誰能幫我出這個關於如何獲得下一個輸入框的值?
是它的工作的第一次?當推測current_item是一個?我在想第二次你在找「box11」和第三次「box111」 – Sap
第一次沒有工作..當我運行它時,它回來說undefined。當我添加var current_item =「1」;到它的工作功能,但從來沒有增加數字,它始終設置爲1. – Aaron