开发者_JS百科May i know how can i batch change a input for other input at javascript example:
<input type="text" id="abc">`<input type="text" id="abc1">`<input type="text" id="abc2">`
<input type="text" id="abc3">`<input type="text" id="abc4">`
the following abc1->abc4 will change according the 1st.
This will get all the inputs in the document and change them to the value of the first.
var masterInput = document.getElementById('abc');
masterInput.onchange = function () {
var inputs = document.getElementsByTagName('input');
for (var i = 1; i < inputs.length; i++) {
inputs[i].value = this.value;
}
};
If you have other inputs in the page (quite likely), you can replace document
with the parent element, or you can iterate through the id
s individually:
var masterInput = document.getElementById('abc');
masterInput.onchange = function () {
var inputs = ['abc1', 'abc2', 'abc3', 'abc4'];
for (var i = 0; i < inputs.length; i++) {
document.getElementById(inputs[i]).value = this.value;
}
};
精彩评论