小编tlq*_*tlq的帖子

如何查找具有数据属性的标记

我试图找到具有data-direction属性的标签.不知何故,它总是未定义的.我所试图做的就是值data-directiondata-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)

html javascript jquery custom-data-attribute

2
推荐指数
1
解决办法
118
查看次数

标签 统计

custom-data-attribute ×1

html ×1

javascript ×1

jquery ×1