您好我正在尝试动态创建一个按钮,但无法获取按钮上的图标。我无法获得显示图标的按钮。我将不胜感激任何帮助。如何在 removeBtn 按钮小部件上设置关闭图标。
var a = [{
"_id": {
"$oid": "50894875744e80aa5fa59853"
},
"name": "Test 1",
"color": "#b63e3e",
"propertyNames": ["Notes"]},
{
"_id": {
"$oid": "50894afe744e80aa5fa59854"
},
"name": "Test 2",
"color": "#413bb6",
"propertyNames": ["Notes"]},
{
"_id": {
"$oid": "50894c23744e80aa5fa59855"
},
"name": "Test 3",
"color": "#95eba5",
"propertyNames": ["Notes"]}];
for (var i = 0; i < a.length; i++) {
var button = document.createElement('span');
button.className = 'color-button';
button.style.backgroundColor = a[i].color;
var selectionItem = document.createElement('li');
selectionItem.id = a[i]._id.$oid;
selectionItem.className = "ui-widget-content";
selectionItem.appendChild(button);
selectionItem.appendChild(document.createTextNode(a[i].name));
$('#id1').append(selectionItem);
var removeBtn = $('<button/>',
{
click: function(){
alert(this.parentNode.id);
}
});
removeBtn.css("float","right");
$("#"+a[i]._id.$oid).append(removeBtn);
}
这是代码的 jsFiddle 链接:http: //jsfiddle.net/vivsriva/VmEeR/5/