简体   繁体   English

jQuery selector | = in $(“[name | ='value']”)

[英]jQuery selector |= in $(“[name|='value']”)

I found this snippet in some javascript code: 我在一些javascript代码中找到了这个代码段:

var name = "someString";
var s = "[name|='"+name+"']";
var nArr = $JQ(s);

Can someone explain what |= does? 有人能解释一下|=什么作用吗?

I can see in my debug tool that I receive an array of jQuery elements, which all have someString in their name. 我可以在我的调试工具中看到我收到了一个jQuery元素数组,它们的名字都有someString But I wasn't able to find an explanation in the jQuery documentation. 但我无法在jQuery文档中找到解释。 What am I missing? 我错过了什么?

This is attribute contains prefix selector 这是属性包含前缀选择器

Selects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-). 选择具有指定属性的元素,其值等于给定字符串或以该字符串开头,后跟连字符( - )。

 $("a[hreflang|='en']").css("color", "green"); 
 a { display: block; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <a href="example.html" hreflang="en">Some text</a> <a href="example.html" hreflang="en-UK">Some other text</a> <a href="example.html" hreflang="english">will not be selected</a> 


This selector was introduced into the CSS specification to handle language attributes. 此选择器已引入CSS规范中以处理语言属性。

W3 W3

Represents an element with the att attribute, its value either being exactly "val" or beginning with "val" immediately followed by "-" (U+002D). 表示具有att属性的元素,其值正好是“val”或以“val”开头,后跟“ - ”(U + 002D)。 This is primarily intended to allow language subcode matches (eg, the hreflang attribute on the a element in HTML) as described in BCP 47 ([BCP47]) or its successor. 这主要是为了允许语言子代码匹配(例如,HTML中元素的hreflang属性),如BCP 47([BCP47])或其后继者所述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM