简体   繁体   English

XPath 在 JQuery 选择器中不起作用(JQuery 版本 1.7.1)

[英]XPath not working in JQuery selector (JQuery version 1.7.1)

Below is a jQuery selector that works, and the value is set correctly into the text box.下面是一个有效的 jQuery 选择器,该值已正确设置到文本框中。 Why doesn't the XPath code within the jQuery selector work?为什么 jQuery 选择器中的 XPath 代码不起作用? I thought jQuery supported XPath.我以为jQuery支持XPath。

jQuery code working: jQuery 代码工作:

$('html > body > form > div:nth-child(4) > label > input').val('hello world');

jQuery code not working: jQuery 代码无效:

$('/html/body/form/div[4]/label/input[1]').val('hello world');

Documentation here:文档在这里:

http://docs.jquery.com/DOM/Traversing/Selectors http://docs.jquery.com/DOM/Traversing/Selectors

... search for this code in the documentation above.... $("/html/body//p") ... 在上面的文档中搜索此代码.... $("/html/body//p")

jQuery does not support XPath syntax for selectors out of the box anymore. jQuery 不再支持开箱即用的选择器的 XPath 语法。

If you look at that documentation you link to, you'll see it's for version 1.1.2 , something from more than 5 years ago.如果您查看链接到的文档,您会看到它是针对版本 1.1.2的,这是 5 年多以前的东西。 It also says, in a great big red box with centered text :它还在一个带有居中文本的大红色框中说:

This is an old version of the Selectors API:这是选择器 API 的旧版本:

View the Current API查看当前 API

When the Xpath selectors were removed ( in JQuery 1.2 ) the functionality was moved to a plugin, http://archive.plugins.jquery.com/project/xpath当 Xpath 选择器被删除时( 在 JQuery 1.2 中),功能被移动到一个插件, http://archive.plugins.jquery.com/project/xpath

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM