开发者

e4x: simplest way to tell if an attribute exists

开发者 https://www.devze.com 2023-02-02 11:13 出处:网络
What\'s the simplest way to tell if an attribute exists? p = <abc name=\"foo\" />; js>p.@name.length()

What's the simplest way to tell if an attribute exists?

p = <abc name="foo" />;


js>p.@name.length()
1
js>p.@zebra.length()
0

I can use @attr.length() but was wondering if there is an isAttributePresent() or som开发者_StackOverflow中文版ething.

NOTE: This is not in a browser, this is just a javascript interpreter based on core Mozilla Javascript 1.8 with E4X enabled.


You can use

'@name' in p

This will return true or false depending on existence of said attribute.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号