如何在JavaScript中添加多个选择器 [英] How to add more than one selector in javascript

查看:101
本文介绍了如何在JavaScript中添加多个选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在JavaScript中添加更多一个变量:

How can i add more the one variable in JavaScript :

var selector = 'a[href$=png]:has(img)';

以便它还可以获取其他格式的图像,例如jpg,jpeg和bmp.

So that it can get images with other format like jpg, jpeg and bmp also.

完整脚本 https://googledrive.com/host/0Bx94NfJgN888WWVnNTk5UHhhbk0

推荐答案

您可以在同一条语句中使用多个选择器来选择与任何一个选择器匹配的内容,例如:

You can use multiple selectors in the same statement to select anything that matches either of your selectors, like so:

$('.selector1, .selector2')

这将匹配选择器选择器2类的任何元素.因此,您可以尝试执行以下操作:

This will match any element with the class selector1 or selector2. Therefore you could try something like the following:

var selector = 'a[href$=png],a[href$=jpg]';
$(selector)...

这篇关于如何在JavaScript中添加多个选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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