JavaScript + e4x:如何测试元素是否为空?
有没有办法使用 e4x 测试 XML 元素是否为空?
例如,如果我有一个元素
,我想返回 true,但如果我有另一个具有任何属性、子元素或文本的元素,我想返回 false。
Is there a way to test whether an XML element is empty using e4x?
e.g. if I have an element <foo />
, I want to return true, but if I have another element that has any attributes, child elements, or text, I want to return false.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚艰难地浏览了 e4x 上的 ECMA-357 v2 规范; XML 节点的方法在 13.4.4 节中列出,并且此测试没有有用的
isXXX()
或hasXXX()
方法;最简单的方法似乎如下:I just slogged through the ECMA-357 v2 spec on e4x; the methods for XML nodes are listed in section 13.4.4, and there are no useful
isXXX()
orhasXXX()
methods for this test; the simplest way to do it seems to be the following: