0
目前我有兩個輸入字段,當我按下更新按鈕時自動更新,我想添加更多的輸入......但問題是我必須手動添加我的輸入字段名稱在jQuery腳本。 我們可以爲此添加任何循環嗎?請幫忙!!jQuery循環的複選框
Type Comment: <input name="mainComment" type="text" value="" />
<input type="button" name="updateComment" value="Update" />
<hr />
<input type="checkbox" class="myCb" name="cb[1]" /><input type="text" name="inv[1]" value="" /><br />
<input type="checkbox" class="myCb" name="cb[2]" /><input type="text" name="inv[2]" value="" />
<script type="text/javascript">
$(document).ready(function() {
$("input[name='updateComment']").live("click", (function(){
if($("input[name='cb[1]']").is(":checked")) {
$("input[name='inv[1]']").val($("input[name='mainComment']").val());
} else {
$("input[name='inv[1]']").val("");
}
if($("input[name='cb[2]']").is(":checked")) {
$("input[name='inv[2]']").val($("input[name='mainComment']").val());
} else {
$("input[name='inv[2]']").val("");
}
}));
});
</script>
['.live()'](http://api.jquery.com/live/)已被棄用,並在較新的jQuery版本中被刪除。我會建議更新你的腳本到['.on()'](http://api.jquery.com/on/) – empiric
Thankyou @empiric –