【发布时间】:2014-03-02 15:52:44
【问题描述】:
<div id="note"></div>
<p>
Item 1
<input name="one" type="checkbox" value="Item 1" />
</p>
<p>
Item 2
<input name="two" type="checkbox" value="Item 2" />
</p>
<p>
Item 3
<input name="anything" type="checkbox" value="Item 3" />
</p>
<br/>
Current issue: Does not work as expected. We want to duplicate the paragraph containing the input field whenever it is clicked (involving updating the name). Constraint - Original html cannot be changed.
脚本(在这篇文章的帮助下)
var plen;
$(document).on('click', 'input[type="checkbox"]', function(){
plen = $('p').length
$(this).parent().clone(true).appendTo('body').attr('id',''+plen)
$(this).prop('checked', true);
//alert(plen)
$('#note').text('More of item '+ plen)
});
我快到了,但距离理想的结果还很远。在 JSFiddle 中解释。
JSFiddle 在这里:http://jsfiddle.net/Sergelie/ULywc/
【问题讨论】: