如何让 CSS 选择以字符串开头的 ID(不是在 Javascript 中)?
- 作者: Schoene
- 来源: 51数据库
- 2022-10-20
问题描述
如果 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.
推荐阅读
热点文章
检查拆分键盘
0
带有“上一个"的工具栏和“下一个"用于键盘输入AccessoryView
0
Activity 启动时显示软键盘
0
UIWebView 键盘 - 摆脱“上一个/下一个/完成"酒吧
0
在 iOS7 中边缘滑动时,使键盘与 UIView 同步动画
0
我的 iOS 应用程序中的键盘在 iPhone 6 上太高了.如何在 XCode 中调整键盘的分辨率?
0
android:inputType="textEmailAddress";- '@' 键和 '.com' 键?
0
禁用 iPhone 中键盘的方向
0
Android 2.3 模拟器上的印地语键盘问题
0
keyDown 没有被调用
0
