我正在尝试使用每个函数,但我需要匹配确切的属性名称
jquery的
$('[data*="name"]').each(function(i, obj){dostuff}
只有在找到名称时才需要 {dostuff} ,而在找到名称时则不需要。任何建议?
答案 0 :(得分:3)
答案 1 :(得分:2)
我认为你应该这样做。
$('[data="name"]').each(function(i, obj){ dostuff });
我希望我帮助过你! :)
答案 2 :(得分:1)
您应该能够使用attribute equals selector,这与*
的当前选择器基本相同(因为*=
用作"contains" selector):
// This would perform your operation to every element that had a data attribute of
// "name" (i.e. <span data="name">, etc.)
$('[data="name"]').each(function(i, obj){
dostuff();
});
答案 3 :(得分:1)
只需
$('[data="name"]').each(function(i, obj){dostuff}
OR
$('[data*="name"]:not([data*=names])').each(function(i, obj){dostuff}
答案 4 :(得分:1)
从属性选择器(*字符)
中删除“contains”条件$('[data="name"]').each(function(i, obj){dostuff}
在属性名称后面使用*
选择具有指定属性的元素 包含给定的子字符串
阅读here