[英]Target element with specific attribute in css
I want to target all the button which has a buttonid starts from tab_btn(number) 我想定位所有具有tabid从tab_btn(number)开始的按钮
Is there a way to select element in css this way. 有没有一种方法可以这样选择css中的元素。 I cannot make use of jquery as CSS is only the restriction. 我不能使用jquery,因为CSS只是限制。
<input id="FormControl_V1_I1_S1_I1_B1" scriptclass="Button" class="dh_LmyGLHecqegKZ42V_0 dj_LmyGLHecqegKZ42V_0" formid="FormControl" originalid="V1_I1_S1_I1_B1" tabindex="0" title="" buttonid="tab_btn1" value="General" type="button">
<input id="FormControl_V1_52_J1_I1_B1" scriptclass="Button" class="dh_LmyGLHecqegKZ42V_0 dj_LmyGLHecqegKZ42V_0" formid="FormControl" originalid="V1_I1_S1_I1_B1" tabindex="0" title="" buttonid="tab_btn2" value="General" type="button">
Class and other attribute wont be constant here, But the ID will have a series starting tab_btn1, tab_btn2 etc 类和其他属性在这里不会保持不变,但是ID会有一个以tab_btn1,tab_btn2等开头的序列
Just do [id^="tab_btn"]
as a selector. 只需将[id^="tab_btn"]
做为选择器即可。 It will target all IDs beginning with tab_btn
它将定位以tab_btn
开头的所有ID
See the docs https://api.jquery.com/attribute-contains-selector/ 参见文档https://api.jquery.com/attribute-contains-selector/
Check this example: 检查以下示例:
Set a background color on all elements that have a class attribute value that begins with "test": 在所有具有以“ test”开头的类属性值的元素上设置背景色:
div[class^="test"] {
background: #ffff00;
}
Attribute selector in css. CSS中的属性选择器。 The [attribute^="value"] selector is used to select elements whose attribute value begins with a specified value. [attribute ^ =“ value”]选择器用于选择属性值以指定值开头的元素。
input[buttonid^= "tab_btn"] { background: yellow; }
<input id="FormControl_V1_I1_S1_I1_B1" scriptclass="Button" class="dh_LmyGLHecqegKZ42V_0 dj_LmyGLHecqegKZ42V_0" formid="FormControl" originalid="V1_I1_S1_I1_B1" tabindex="0" title="" buttonid="tab_btn1" value="General" type="button"> <input id="FormControl_V1_52_J1_I1_B1" scriptclass="Button" class="dh_LmyGLHecqegKZ42V_0 dj_LmyGLHecqegKZ42V_0" formid="FormControl" originalid="V1_I1_S1_I1_B1" tabindex="0" title="" buttonid="tab_btn2" value="General" type="button"> <input id="FormControl_V1_H2_M1_I1_B1" scriptclass="Button" class="dh_LmyGLHecqegKZ42V_0 dj_LmyGLHecqegKZ42V_0" formid="FormControl" originalid="V1_J1_T1_I1_B1" tabindex="0" title="" buttonid="tab2" value="General" type="button">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.