jquery:选择xpath还是将xpath转换为css? [英] jquery: selecting xpath or converting xpath to css?

查看:91
本文介绍了jquery:选择xpath还是将xpath转换为css?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据xpath选择,或者将xpath转换为css。



是否有插件或内置功能。<​​/ p>

ex。 $('/ html / body / div / a [4]')。each ....

解决方案

并非所有的xpath表达式都可以转换为类似CSS的选择器,或者不能有效地工作。您可以使用:eq 选择器按索引访问元素,但建议您使用 eq 方法代替。这相当于您示例中的xpath:

  $('html> body> div> a') .eq(3).each(... 


i need to select based on xpath , or convert xpath to css.

is there a plugin or built in function.

ex. $('/html/body/div/a[4]').each ....

解决方案

Not all xpath expressions are possible to translate to CSS-like selectors, or doesn't work efficiently. You can use the :eq selector to access elements by index, but it's recommended that you use the eq method for this instead. This would be equivalent of the xpath in your example:

$('html > body > div > a').eq(3).each( ...

这篇关于jquery:选择xpath还是将xpath转换为css?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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