$('*[data-customerID="22"]');
You should be able to omit the *
, but if I recall correctly, depending on which jQuery version you're using, this might give faulty results.
(您应该可以省略*
,但是如果我没记错的话,根据您使用的jQuery版本,这可能会导致错误的结果。)
Note that for compatibility with the Selectors API ( document.querySelector{,all}
), the quotes around the attribute value ( 22
) may not be omitted in this case .
(请注意,为了与Selectors API( document.querySelector{,all}
)兼容, 在这种情况下,可能会省略属性值( 22
)周围的引号。)
Also, if you work with data attributes a lot in your jQuery scripts, you might want to consider using the HTML5 custom data attributes plugin .
(另外,如果您在jQuery脚本中大量使用数据属性,则可能需要考虑使用HTML5自定义数据属性插件 。)
This allows you to write even more readable code by using .dataAttr('foo')
, and results in a smaller file size after minification (compared to using .attr('data-foo')
). (这使您可以通过使用.dataAttr('foo')
编写更具可读性的代码,并在缩小后产生更小的文件大小(与使用.attr('data-foo')
)。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…