我正在尝试找到一种方法来突出显示表单中的一些必填字段。 我无法访问此应用程序的标签设置,因此我想尝试在标签中找到一个字符并将其更改为更突出。
必填字段的当前标签设置为此示例:
<label>First Name *</label>
我想在页面中找到星号* 的标签标签的所有实例,并将它们包装在CSS类中,这样我就可以设置颜色或替换为图像。 这是可以实现的吗?
提前谢谢。
答案 0 :(得分:5)
查找所有标签都包含星号, 用你的元素替换html
$("label:contains('*')").each(function(){
var r = $(this).html().replace('*',','<sup class="conditions">*</sup>');
$(this).html(r);
});
but this could be done much nicer/faster with css:
label.requiredField:after {
content: "*";
color:#f00;
}
/** your HTML would be **/
<label class="requiredField">First Name</label>
/** and renders like: **/
First Name*
答案 1 :(得分:2)
:contains
选择器可让您满意:
$('label:contains("*")').wrap('<span style="color:red">');
答案 2 :(得分:0)
$(label).filter(function () {
return $(this).text().indexOf('*') != -1;
}).each(function () {
$(this).whatEver();
});