jquery – 从模板元素创建元素?

我有一些麻烦:
template = $("#template");
$(template).attr("id","newid");

$(template).appendTo("body");

我想做的是为模板分配一个id,然后修改内容.麻烦的是,我目前是指实际的模板元素,所以id正在改变.再次使用这个模板,我不能选择,因为id是不同的.

任何关于最佳方法的建议?

解决方法

克隆对象:
template = $("#template").clone();
template.attr("id","newid");
template.appendTo("body");

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...