我正在尝试使用 jquery 从属性中获取 31003 值。
<a class= "findOption" data-clickaction="changeFilter" data-actionvalue=" {"Company":"31003", "val": "mostrecent";}" href="javascript:void(0);">Most Recent</a>
我已经尝试过了,
$(".findOptions").attr('公司').value();
$(".findOptions").attr('data-actionvalue');
我被困住了。
最佳答案
您可以使用data method :
$('.findOption').data('actionvalue')['Company'];//findOption instead as noticed by @Vimalan
正如 @Barmar 指出 html 无效,你应该在 html 中这样做:
data-actionvalue='{"Company":"31003", "val": "mostrecent"}'
关于javascript - 使用jquery获取属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31082934/