以下代码运行正常。任何人都帮助我同样的情况 http://jsbin.com/axohar/3
$(function(){
$('input:checkbox').click(function(){
var id = this.id; // No need for `attr`
if(this.checked){ // No need for `attr`
$("<div>")
.text($(this.parentNode).text())
.attr("data-contents", id)
.appendTo("#members");
}
else {
$('div[data-contents="' + id + '"]').remove();
}
});
});
而不是标签我需要超链接(html)。原因是我想在运行时列出所有带超链接的字段。
<a href="tag_a.asp">The a tag1</a>
<a href="tag_a.asp">The a tag1</a>
example
link1
link2
link3
答案 0 :(得分:0)
您可以使用html()
并以这种方式在div中附加锚标记:
$("<div>")
.html('<a href="http://www.google.com">'+$(this.parentNode).text()+'</a>')
.attr("data-contents", id)
.appendTo("#members");