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

时间:2012-04-10 16:47:37

标签: jquery xpath jquery-selectors jquery-1.7

下面是一个可以工作的jQuery选择器,并且值正确地设置在文本框中。为什么jQuery选择器中的XPath代码不起作用?我认为jQuery支持XPath。

jQuery代码正常工作:

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

jQuery代码无效:

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

此处的文档:

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

...在上面的文档中搜索此代码.... $("/html/body//p")

2 个答案:

答案 0 :(得分:7)

jQuery不再支持开箱即用的选择器的XPath语法。

如果您查看链接到的文档,您会看到版本1.1.2 ,这是5年多以前的事情。它还说,在一个伟大的大红色框中心文本

  

这是Selectors API的旧版本:

     

View the Current API

答案 1 :(得分:3)

删除Xpath选择器(in JQuery 1.2)后,功能已移至插件http://archive.plugins.jquery.com/project/xpath