[英]jQuery find all elements with certain attribute and get the value of it
I need to get values of every existing 'ajaxify' attribute on the page. 我需要获取页面上每个现有“ ajaxify”属性的值。
$('[ajaxify]')
This gets me 361
objects. 这使我获得361
对象。 How to get the values? 如何获得价值?
To get all value as an array, use map()
, attr()
and get()
methods 要获取所有值作为数组,请使用map()
, attr()
和get()
方法
$('[ajaxify]').map(function() {
return $(this).attr('ajaxify')
}).get()
FYI : Always try to use data-*
(eg : data-ajaxify
) for custom attribute, since it's the standard way to use custom attribute. 仅供参考:始终尝试对自定义属性使用data-*
(例如: data-ajaxify
) ,因为这是使用自定义属性的标准方法。 In than case you can use data()
method to get attribute value. 在这种情况下,可以使用data()
方法获取属性值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.