我目前得到的是一个问题,我想要更改id与输入类型匹配的每个元素值。请看看我的jsFiddle,这应该为你清理很多。问题是值不会改变所有输入类型,它只会改变该ID的第一个输入类型。尝试使用.each函数,但没有帮助。更改具有相同编号的输入类型的所有值
HTML
<input type="text" id="first" value="tesdafsdf" />
<input type="text" id="second" />
<input type="text" id="second" />
<input type="text" id="second" />
<input type="text" id="second" />
<input type="text" id="second" />
<input type="text" id="second" />
<input type="text" id="second" />
<input type="text" id="second" />
jQuery的
$('#first').keyup(function() {
updateSearch();
});
var updateSearch = function() {
$('#second').each(function(index, value) {
this.value = $('#first').val();
});
};
//Change the values for testing purpose
updateSearch();
http://jsfiddle.net/ZLr9N/377/
ID必须是相同的..使用类 – 2015-04-01 09:51:58
@ArunPJohny等待什么实际工作,你们能不能进一步elleborate这是为什么?这对我来说毫无意义。 – Jordy 2015-04-01 09:53:24
这有一些解释** [Id必须是唯一的](http://programmers.stackexchange.com/a/127180)** – 2015-04-01 09:55:07