Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 通过rel和类同时获取元素?_Jquery - Fatal编程技术网

Jquery 通过rel和类同时获取元素?

Jquery 通过rel和类同时获取元素?,jquery,Jquery,考虑下面的HTML: <a class="box" rel="1"> link </a> <a class="box" rel="8"> link </a> 一种可能的办法: $('.box[rel="' + numberToLookFor + '"]'); // or just $('.box[rel=1]'), if this number is static 。。。换句话说,只需将两个简单选择器放在一起,即可创建一个组合选择器

考虑下面的HTML:

 <a class="box" rel="1">  link </a>
 <a class="box" rel="8">  link </a>
一种可能的办法:

$('.box[rel="' + numberToLookFor + '"]'); 
// or just $('.box[rel=1]'), if this number is static
。。。换句话说,只需将两个简单选择器放在一起,即可创建一个组合选择器


请注意,
.box
和方括号之间不应存在空格,否则方括号将检查
.box
子体。

您可以尝试使用jQuery的:

以下是一个例子:

$("[attribute='value']").someEvent();

你说“第一”是什么意思?很抱歉。这是一个错误。
$("[attribute='value']").someEvent();