tlq*_*tlq 2 html javascript jquery custom-data-attribute
我试图找到具有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)
问题出在这一行:
var tr = $(elem).find("tr.data-cellId");
Run Code Online (Sandbox Code Playgroud)
该.data-cellId部件基于具有该类的元素进行选择.要查找属性,请[data-cellId]在选择器中使用:
var tr = $(elem).find("tr[data-cellId]");
Run Code Online (Sandbox Code Playgroud)
然后,要获取该属性的值,您可以使用:
tr.attr('data-cellId');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
118 次 |
| 最近记录: |