我想在每个必需的标签上添加必需的(*)

Nav*_*ari 1 css jquery

我要求使用红色星号标记.我需要带有标签的类,这些标签是我的应用程序中必填字段.应用程序中有很多表单.我使用下面的代码尝试使用jquery.

  $(".required").each(function(){
   $(this).prepend("<span class='red'>*</span>");
  });
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我用css来应用它.帮助将不胜感激.

ish*_*ood 6

为什么不只是CSS?

label.required::before {
  content: '*';
  margin-right: 4px;
  color: red;
}
Run Code Online (Sandbox Code Playgroud)
<form>
  <label for="input1" class="required">Label One</label>
  <input type="text" id="input1" />
</form>
Run Code Online (Sandbox Code Playgroud)