本文介紹了如何讓 CSS 選擇以字符串開頭的 ID(不是在 Javascript 中)?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
如果 HTML 有這樣的元素:
If the HTML has elements like this:
id="product42"
id="product43"
...
如何匹配所有以產品"開頭的 id?
How do I match all of those id's starting with "product"?
我已經看到完全使用 javascript 執行此操作的答案,但是如何僅使用 CSS 執行此操作?
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".
這些符號實際上是從 Regex 語法中借用的,其中 ^
和 $
分別表示字符串開頭"和字符串結尾".
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 選擇以字符串開頭的 ID(不是在 Javascript 中)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!