Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.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
Javascript 针对包含值的属性的jQuery_Javascript_Jquery - Fatal编程技术网

Javascript 针对包含值的属性的jQuery

Javascript 针对包含值的属性的jQuery,javascript,jquery,Javascript,Jquery,在以下HTML结构中: <div class="someclass" tabindex="0" aria-describedby="my-specified-action my-one-name"> <div class="someclass" tabindex="1" aria-describedby="my-specified-action my-two-name"> <div class="someclass" tabindex="2" aria-descri

在以下HTML结构中:

<div class="someclass" tabindex="0" aria-describedby="my-specified-action my-one-name">
<div class="someclass" tabindex="1" aria-describedby="my-specified-action my-two-name">
<div class="someclass" tabindex="2" aria-describedby="my-specified-action my-three-name">
<div class="someclass" tabindex="3" aria-describedby="my-specified-action my-four-name">
<div class="someclass" tabindex="3" aria-describedby="my-specified-action my-five-name">
当然,如果我愿意:

jQuery('div:not([aria-describedby*="four"])').hide()
它将隐藏所有元素(也包括包含我的目标..)

出于某种原因,这对我来说不起作用

jQuery('div:not([aria-describedby^="four"])').hide()

我做错了什么???

您的问题不是属性选择器,而是目标元素选择器

您正在隐藏其
aria descripeby
属性不包含
four
的所有div元素,相反,您需要微调选择器以仅针对您想要的那些元素。在您的情况下,因为所有div共享类
someclass
,所以请像这样使用它

jQuery('div.someclass:not([aria-describedby*="four"])').hide()

演示:

因为没有以
four开头的属性值,所以第二个代码很好并没有隐藏所有元素-第一个也很好-是不是
*
代表
包含
?(对不起,我对任何不是PHP的东西都很不了解)阅读谢谢!我想要这个。但它现在可以工作了…你能简单地解释一下顶部的附加代码吗?为什么需要它@ObmerkKronen您的代码
jQuery('div:not([aria descripeby*=“four”])。hide()
表示隐藏所有
div
元素,但不包含
aria descripeby
属性。现在您有了一个container div,它没有
aria descripbeby
属性,因此它为条件返回true,从而得到hidden@ObmerkKronen你能告诉我你想要哪种解释吗?我指的是代码
return$(this.attr('aria-descripeby')
。对不起,我只是想学习和理解更多
jQuery('div.someclass:not([aria-describedby*="four"])').hide()