【发布时间】:2020-03-28 01:16:22
【问题描述】:
我有以下表结构:
<th data-column-index="7">Total Activity Amount
<a class="btn btn-app btn-default filterStyle" onclick="getFilter(this)">
<i class="fa fa-filter f_7" aria-hidden="true"></i>
</a>
</th>
单击 getFilter() OnClick 事件时,我需要获取“数据列索引”值。我已经尝试过以下在 Onclick 事件中获取父值的方法
function getFilter1(e){
var evID=$(e).parent().find('data-column-index').val();
alert(evID);
}
或
var evID = $(this).parent('thead th').attr("data-column-index");
或
var evID = $(this).closest('th').attr("data-column-index");
我得到相同错误的所有原因,例如“错误!内容未定义。
请帮我解决这个问题。谢谢
请注意: 'data-column-index' 是 J Query Data 表中的动态值,当我们改变位置时它会自动更新。所以我不能直接将此值添加到点击事件中
【问题讨论】:
-
你试过这个
$(e).parent().data('column-index')吗? -
你也不能使用
this,因为你还没有使用jquery绑定——你直接使用onclick绑定,然后将this作为e传递给你的函数 -
@AliShahbaz。抱歉,我没有尝试使用该选项。现在它正在工作。谢谢
-
@AliShahbaz 抱歉,我的“列索引”是动态设置的数据属性。所以我不能使用数据()。有没有替代品?
标签: javascript jquery