一个document.createElement,将它追加两次,只显示一次 [英] one document.createElement, append it twice, only shows once
本文介绍了一个document.createElement,将它追加两次,只显示一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在页面的开头和结尾使用一个按钮:
I have a button I want to use in the beginning and the end of the page:
var button_save = document.createElement('button');
$("#compteurs").append(button_save);
[...]
$("#compteurs").append(button_save);
但它只出现在页面的末尾。如果我从页面底部删除它,它将出现在页面的开头。这是一种指针。有没有办法只创建一次按钮并使用它两次?谢谢!
but it only appear at the end of the page. If I remove it from the bottom of the page, it appear at the begining of page. It's a kind of pointer. Is there a way to create the button only once and use it twice? Thanks!
推荐答案
您可以使用 .clone()
,如下所示:
You can use .clone()
, like this:
var button_save = $("<button />");
$("#compteurs").append(button_save);
[...]
$("#compteurs").append(button_save.clone());
这篇关于一个document.createElement,将它追加两次,只显示一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文