如何获取CSS选择以字符串(不是Javascript)开头的ID? [英] How to get CSS to select ID that begins with a string (not in Javascript)?
本文介绍了如何获取CSS选择以字符串(不是Javascript)开头的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果HTML包含如下元素:
id =product42
id =product43
...
如何匹配所有这些以product开头的id? / p>
我已经看到了使用javascript完成这些操作的答案,但是如何只使用CSS?
解决方案
[id ^ = product]
$ b b
^ =
表示开头为。相反, $ =
表示结束于。
符号实际上是从Regex语法借用的,其中 ^
和 $
分别表示字符串开始和字符串结束。
请参阅规格了解完整信息。
If the HTML has elements like this:
id="product42"
id="product43"
...
How do I match all of those id's starting with "product"?
I've seen answers that do this exactly using javascript, but how to do it with only CSS?
解决方案
[id^=product]
^=
indicates "starts with". Conversely, $=
indicates "ends with".
The symbols are actually borrowed from Regex syntax, where ^
and $
mean "start of string" and "end of string" respectively.
See the specs for full information.
这篇关于如何获取CSS选择以字符串(不是Javascript)开头的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文