HTML:jQuery將不會添加元素上工作
<fieldset>
<select>
<option value="">Position</option>
</select>
<input type="text" />
<select>
<option value="">Function</option>
</select>
<input type="button" class="buttonAnd" value="And" />
<input type="button" class="buttonOr" value="Or" />
</fieldset>
的jQuery:
$(document).ready(function() {
field_count = 0;
$(".buttonAnd").click(function(){
field_count++;
$('fieldset').append(jQuery("<br />"));
var new_field = jQuery("<input type=\"button\" />")
new_field.attr("class","buttonAnd");
new_field.attr("name","buttonAnd_"+field_count);
new_field.attr("value","And_"+field_count);
$('fieldset').append(new_field);
});
});
追加新的按鈕,只能在原來的兩個按鈕的工作原理,但它不工作新產生的按鈕。任何想法如何解決這個問題?
Tnx!
Thanx Travis J!我試過你的解決方案,它的工作原理。感謝所有其他人!
做一個純粹的JS函數,從html元素 – Memolition 2013-04-29 19:12:55
稱它爲ID添加到按鈕(例如:'鍵+ counter')和ID稱之爲 – 2013-04-29 19:33:08