我试图找到具有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);
Run Code Online (Sandbox Code Playgroud)
事件监听
$(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())
});
Run Code Online (Sandbox Code Playgroud)