我正在尝试查找具有data-direction
属性的标签。不知何故,它总是未定义的。我想要做的是得到data-direction
和data-cellId
的值。 有什么建议吗?如何查找具有数据属性的标签
var row = $('<tr data-cellId="' + cell.fatherId + '" data-direction="' + cell.direction + '"/>');
var nameColumn = $('<td class="port-name-col" data-cellId="' + cell.fatherId + '">' +cell.value.name + '</td>');
var btnColumn = $('<td class="port-btn-col"><button type="button" title="Remove" class="btn btn-default btn-xs x-button-icon btn-delete-port"><span class="glyphicon glyphicon-trash"></span></button></td>');
row.append(nameColumn);
row.append(btnColumn);
事件监听
$(document).off('click', '.btn-delete-port').on('click', '.btn-delete-port', function (event) {
var elem = event.target || event.srcElement;
//find tr element that has cellID attribute
var tr = $(elem).find("tr.data-cellId");
alert($(elem).parent().parent().html())
});
尝试使用['.attr()'](HTTPS ://api.jquery.com/attr/) – Und3rTow
使用这个'$(elem).find(tr [data-cellId]);' –
您是否在任何点向DOM添加'row'? – Curt