我有2個按鈕,它們都顯示像下面兩次:我要顯示的按鈕一次,而不是兩次
Button 1 (Performs the onclick='SelectAll(this)')
Button 1 (Performs the onclick='RemoveAll(this)')
Button 2 (Performs the onclick='SelectAll(this)')
Button 2 (Performs the onclick='RemoveAll(this)')
兩個按鈕1和按鈕2應該出現一次象下面這樣:
Button 1 (Performs the onclick='SelectAll(this)')
Button 2 (Performs the onclick='RemoveAll(this)')
我怎樣才能實現這一點以上:
,其顯示該代碼這些按鈕下面:
function insertButton(form) {
var $answer = $("<table class='answer'></table>");
$('.buttonOne:first, .buttonTwo:first').each(function() {
var $this = $(this);
var $BtnsClass = '';
$row = $("<tr/>").appendTo($answer);
$cell = $("<td/>").appendTo($row);
$BtnsClass = $("<input class='buttonOne btnsAll' type='button' style='display: block;' value='Button 1' onClick='selectAll(this);' />
<br/>
<input class='buttonTwo btnsRemove' type='button' style='display: block;' value='Button 2' onClick='removeAll(this);' />")
.attr('name', $this.attr('name')).attr('value', $this.val()).attr('class', $this.attr('class'));
$BtnsClass.appendTo($cell);
});
$tr.append($answer);
}
下面是HTML凡在jQuery的按鈕應該匹配
<p><input class="buttonOne btnsAll" name="allBtnsName" type="button" value="Button 1" onClick="selectAll(this);" />
<br/><input class="buttonTwo btnsRemove" name="allRemoveBtnsName" type="button" value="Button 2" onClick="removeAll(this);" /></p>
的HTML按鈕只顯示每個按鈕一次,這是很好的,所以爲什麼jQuery的顯示兩次,而不是一次按鈕?
試圖消除循環? – Johan
你喜歡做什麼?你的代碼很混亂。 –
就像我上面說的那樣,它應該只顯示按鈕1一次而按鈕2只顯示一次。目前它正在顯示它們兩次 – BruceyBandit