如何克隆一个元素特定次数
克隆具有指定次数(例如 5 次)的元素的语法是什么? 例如,在 html 中,我有这个元素
<div name="test">
this is a test
</div>
,并且有一个克隆按钮,每当我点击它时,它就会复制该元素。那么问题是我怎么能只想复制它 5 次,这意味着在第五次单击复制按钮后,我将无法复制该元素并收到“已经超出最大值”之类的警报?提前致谢!
what's the syntax to clone an element with assigned times like 5 times?
For example, in the html I have this element
<div name="test">
this is a test
</div>
and I have this clone button which will copy the element once very time I hit it. Then the problem is how can I like just want to copy it 5 times which means after the fifth time I click the copy button, I won't be able to copy the element and get an alart like "already excess maximum "? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯……
并记录您调用
.clone()
的次数。非常简单。示例:
http://api.jquery.com/clone/
Ummm...
... and keep a counter on the number of times you call
.clone()
. Its very simple.Example:
http://api.jquery.com/clone/
JS 小提琴
http://jsfiddle.net/DXcQQ/22/
HTML
JS
JS Fiddle
http://jsfiddle.net/DXcQQ/22/
HTML
JS