如果必填框为空白,则突出显示标签

Highlighting Labels if Mandatory box in blank

我需要帮助。

我需要创建一个案例,在留空时突出显示文本框。

即if CustName = "" then (突出显示并设置焦点)

我使用大小写而不是简单的 if 语句的原因是有 7 个必填输入框框。

任何建议将不胜感激。

谢谢

您可以使用简单的 jQuery.

验证表单的输入

<input type="text" name="CustName" class="input-box" />

只需使用 jQuery 提交事件验证此输入。

$("#form-id").submit(function (event) {
  if ($("CustName").val() == '') {
    $("CustName").focus(); // To set the focus on this text box
    $("CustName").addClass("highlight"); // To highlight input box
  }
}