假设我正在寻找具有属性数据语言"的所有元素,其值以java"开头(将匹配java"和javascript").我知道该怎么做:
Say I'm looking for all elements with an attribute 'data-language', whose value begins with 'java' (would match both 'java' and 'javascript'). I know how to do this:
$('[data-language^="java"]')
但我的问题是:如何获取所有具有属性的元素(不是属性的值,而是实际的属性名称本身)?例如:
But my question is: how do I get all elements that have an attribute (not the value of the attribute, but the actual attribute name itself) beginning with something? For example:
没有捷径,可以使用attributes集合:
There is no shortcut, you may use the attributes collection :
$(someselector).filter(function(){
var attrs = this.attributes;
for (var i=0; i<attrs.length; i++) {
if (attrs[i].name.indexOf("someStartOfName")==0) return true;
}
return false;
});
这篇关于jQuery - 选择属性名称(不是值)以...开头的所有元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Math.random() 在密码学上是安全的吗?Is Math.random() cryptographically secure?(Math.random() 在密码学上是安全的吗?)
在javascript中保护随机数?Secure random numbers in javascript?(在javascript中保护随机数?)
使用过期令牌发出同时 API 请求时如何避免多个令How to avoid multiple token refresh requests when making simultaneous API requests with an expired token(使用过期令牌发出同时 API 请求时如何
JWT 未解码“JWT malformed";- 节点角度JWT not decoding quot;JWT malformedquot; - Node Angular(JWT 未解码“JWT malformed;- 节点角度)
如何使没有到期时间的 JWT 令牌无效How to invalidate a JWT token with no expiry time(如何使没有到期时间的 JWT 令牌无效)
img src 链接中的授权标头Authorization header in img src link(img src 链接中的授权标头)