Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个代码:
$("#addbt").click(function () { $('#choice').clone() .attr('id', 'choice' + $('.ddl').length) .attr('name', 'choice' + $('.ddl').length) .insertAfter(".ddl:last"); });
我是 Jquery 的新手。如何将克隆数停止为特定数字?(比如说 10 个)
在保持与您当前拥有的代码结构大致相同的同时,最简单的方法是使用如下计数器:
counter = 0; $("#addbt").click(function () { counter++; if (counter <= 10){ $('#choice').clone() .attr('id', 'choice' + $('.ddl').length) .attr('name', 'choice' + $('.ddl').length) .insertAfter(".ddl:last"); }); } }