我有以下链接:
<a href="edit/2" class="popup" data-toggle="modal" data-target="#productVariantModal"> <span class="glyphicon glyphicon-edit"></span></a>
我想动态获取数据目标,这样我就可以重用我的 javescript 代码。
我试过这样的:
var target = $(this).closest('[data-target]');
但这行不通。
欢迎提出任何建议。
谢谢。
最佳答案
您需要 #productVariantModal
对吧? So.Simple 使用attr
var getValue = $('.popup').attr("data-target");
如果是动态的
var getValue = $(this).attr("data-target");
关于javascript - 动态获取数据目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23590918/