我有一个要求,需要用红色星号标记。我需要带有标签的类,这些标签是我的应用程序中的必填字段。申请表中有很多表格。我正在使用下面的代码尝试使用jquery。
$(".required").each(function(){
$(this).prepend("<span class='red'>*</span>");
});
有人可以帮我使用 css 来应用它吗?帮助将不胜感激。
最佳答案
为什么不只是 CSS?
label.required::before {
content: '*';
margin-right: 4px;
color: red;
}
<form>
<label for="input1" class="required">Label One</label>
<input type="text" id="input1" />
</form>
关于jquery - 我想为每个必需的标签添加 required(*),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32075600/