在网页中查找具有多个属性的元素 [英] finding a element in web page with multiple properties

查看:116
本文介绍了在网页中查找具有多个属性的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在具有类属性和/或id属性和/或href属性的网页上找到链接.

I need to find link on a web page which has class property and/or id property and/or href property.

因此,在设计时,我不知道链接将具有哪些属性.它可以具有一个或两个或三个属性.

So at design time I would not know what properties that link would have. It could have either one or any two or all three properties.

学习后,我发现在jquery中找到带有href的元素,以下代码有效-

After studying I have figured out to find an element with href in jquery the following code works-

$("a[href='http://www.google.com/']")

类似地,找到具有id和class的元素也可以.

Similarly finding an a element with id and class also works.

我想找出的是如何找出href值为' http://www的元素.google.com/"和/或"abc"的类值和/或"xyz"的id值

What I would like to figure out is howto find out an element which has a href of value 'http://www.google.com/' and/or class value of 'abc' and/or id value of 'xyz'

推荐答案

使用逗号(,)以类似于OR的方式将选择器连接在一起:

Use a comma (,) to join selectors together in an OR-like fashion:

$("a[href='http://www.google.com'], a.abc, a#xyz")

这篇关于在网页中查找具有多个属性的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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