我正在動態構建表單。我將輸入的id標記重命名爲特定值(以便稍後可以參考它們)。當我包含一個複選框輸入時,我最終會收到一個收音機(或至少是奇怪的行爲)與單獨的複選框。 Fiddle來說明這個問題...如何克隆jQuery UI複選框?
HTML
<div id='first'>
<input type="checkbox" id="some-0"><label for="some-0">My Label</label></input>
</div>
<div id='second'>
<input type="checkbox" id="some-1"><label for="some-1">My Label</label></input>
</div>
的JavaScript
$('[id^=some]').button();
var temp = $('#second').clone(true);
temp.find('input').each(function(){
var NAME = $(this).attr('id').split('-');
var LINEcount = 2;
$(this).attr('id',NAME[0]+'-'+LINEcount);
});
$('body').append(temp);
它看起來像你的克隆功能複製的onClick監聽器,這可以解釋爲什麼它切換兩個按鈕。 – softwarenewbie7331 2014-12-08 02:03:58
我發現了更奇怪的行爲:http://jsfiddle.net/shaun5/ms163u6L/2/ – shaun5 2014-12-08 02:24:24