e4x:如何最好地检查属性是否存在?
我知道我可以使用 length() 方法来做到这一点:
>x = <a attr1='33' />
>x.@attr1
33
>[email protected]()
1
>[email protected]()
0
所以我可以使用
if ([email protected]() > 0)
{
.... do something ....
}
,但是有更合适的方法吗?
I know I can do it with the length() method:
>x = <a attr1='33' />
>x.@attr1
33
>[email protected]()
1
>[email protected]()
0
so I could use
if ([email protected]() > 0)
{
.... do something ....
}
but is there a more appropriate way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没关系,我通过仔细研究Ecma-357 标准<找到了答案/a>,特别是 XML.prototype.* 和 XMLList.prototype.* 第 13.4 和 13.5 节。
这是
hasOwnProperty()
方法:Never mind, I found the answer by poring through the Ecma-357 standard, particularly the XML.prototype.* and XMLList.prototype.* sections 13.4 and 13.5.
It's the
hasOwnProperty()
method:最简单的方法:
如果 id 属性存在,则返回 true,否则返回 false。
easiest way:
this will return true if id attrtibute exists and false otherwise.