Javascript获取节点的XPath [英] Javascript get XPath of a node

查看:27
本文介绍了Javascript获取节点的XPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何要在 Javascript 中返回一个 DOM 元素的 XPath 字符串?

Is there anyway to return an XPath string of a DOM element in Javascript?

推荐答案

节点没有唯一的 XPath,因此您必须决定构建路径的最合适方法.在可用的情况下使用 ID?数字在文档中的位置?相对于其他元素的位置?

There's not a unique XPath to a node, so you'll have to decide what's the most appropriate way of constructing a path. Use IDs where available? Numeral position in the document? Position relative to other elements?

请参阅 这个答案 一种可能的方法.

See getPathTo() in this answer for one possible approach.

这篇关于Javascript获取节点的XPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆