XPath 元素/对象在使用 document.evaluate 时未定义
XPath element/object is undefined when using document.evaluate
如何修复常规的JavaScript代码,使其不会显示"未定义"并显示输入字段的值? jQuery 代码工作正常,并在同一页面上正确显示输入字段值。
常规 JavaScript:
var obj = document.evaluate('//html/body/form/div[4]/label/input',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
alert(obj.value);
JQuery 1.7.1 代码:
var obj = $('html > body > form > div:nth-child(4) > label > input');
alert(obj.value);
> document.evaluate()
返回一个 XPathResult。您可以像这样检索元素:
var obj = document.evaluate('//html/body/form/div[4]/label/input', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if(obj != null) {
alert(obj.value);
}
相关文章:
- 正在寻找比$(document).ready慢的$(window).load的替代方案
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 如何用更合适的内容替换document.write
- document.styleSheets不返回任何内容
- jQuery document.ready not working
- $(document).height()在刷新时随机化值(Safari 5.1.10)
- reactjs this.refs vs document.getElementById
- 如何通过adf中的document.getElementById获取inputText字段值
- window.opener.document在ie中不起作用
- contentWindow.document.body is null
- document.applet.method在Mounatin Lion上抛出safari 6+JDK7异常
- document.getElementById(“st”).click();不起作用
- document.evaluate with XPathResult.FIRST_ORDERED_NODE_TYPE 返
- JS: difference between document.evaluate(".//html"
- document.evaluate allways 在某些页面站点上的 singleNodeValue 中返回 nu
- XPath 元素/对象在使用 document.evaluate 时未定义
- Document.evaluate for documents without namespaceURI crashes
- 如何使用document.evaluate查询svg元素
- 突出显示来自javascript: document的html.Evaluate返回空节点
- document.evaluate in chrome and firefox