假设我有一个简单的 XHTML 文档,它为属性使用自定义命名空间:
<html xmlns="..." xmlns:custom="http://www.example.com/ns">
...
<div class="foo" custom:attr="bla"/>
...
</html>
如何使用 jQuery 匹配具有特定自定义属性的每个元素?使用
$("div[custom:attr]")
不起作用。 (到目前为止,仅尝试使用 Firefox。)
最佳答案
jQuery不直接支持自定义命名空间,但是可以通过过滤功能找到你要找的div。
// find all divs that have custom:attr
$('div').filter(function() { return $(this).attr('custom:attr'); }).each(function() {
// matched a div with custom::attr
$(this).html('I was found.');
});
关于javascript - jQuery 属性选择器 : How to query for an attribute with a custom namespace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/91518/