如何在jQuery中选择data-id和data-action

这是对这个问题的后续跟进: 使用javascript:函数语法与jQuery选择器进行Ajax调用

我该如何选择这个片段?

here is my answer

我有下面的id值并试过这个

  $('.add-to-list[data-action|="action-follow-global-id"][data-id|=id]').text('here is the things jtjt in the id value'); 

但没有骰子。 需要和他们在一起。

请求帮助

没有测试,但应该工作:

 var id = 54; $('.add-to-list[data-action=follow-global-id][data-id='+id+']').text('something'); 

这将有效:

 $('.add-to-list[data-action="follow-global-id"][data-id="54"]'). text('here is the things jtjt in the id value'); 

这是一个完整的代码示例,您可以执行以测试:

    
here is my answer

这是你在找什么?

 $('.add-to-list[data-action|="follow-global-id"][data-id]').each(function (i) { $(this).text('here is the things ' + $(this).attr('data-id') + ' in the id value'); }); 

你需要做的就是

 $("[data-action=value") 

要么

 $("[data-id=value"])