假设我有几个输入,
<input type="text" name=ABC onkeyup='MyFunction(this)'>
<input type="text" name=ABC>
<input type="text" name=ABC>
function MyFunction(activeInput) {
/*... some code here to create array 'thisArray', of length 3 whose values are to be assigned to the 3 inputs. ...*/
activeInput.value = thisArray[0];
/*... this is where i need help. How do i assign the other 2 values to other 2 inputs...*/
}
这些输入没有 ID,但具有相同的名称。没有 JQuery,只有 Javascript。
提前致谢!
最佳答案
//not tested
<input type="text" name=ABC onkeyup='MyFunction(this,0)'>
<input type="text" name=ABC onkeyup='MyFunction(this,1)'>
<input type="text" name=ABC onkeyup='MyFunction(this,2)'>
function MyFunction(activeInput,position) {
activeInput.value = thisArray[position];
}
我认为分配和 ID 也会更容易。
activeInput.value = thisArray[activeInput.id];
关于javascript - 如何访问当前事件输入旁边的输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8458975/