gpt4 book ai didi

jquery - 如果发现错误如何突出显示表行 - Jquery

转载 作者:行者123 更新时间:2023-11-28 17:56:51 24 4
gpt4 key购买 nike

这是 jQuery:

$(function() {
$("#register-form").validate({
rules: {
fname: "required",
surname: "required",
middlename: "required",
},
messages: {
fname: "Please enter your name",
surname: "Please specify your surname",
middlename: "Please specify your surname",

},
submitHandler: function(form) {
form.submit();
}

});
});

这是我的 HTML:

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"  method="post"     id="register-form">
<table width="614" border="0">
<tr style="<?php echo $errorname_css; ?>">
<td width="153">First Name</td>
<td width="175">
<input type="text" name="fname" value="<?php echo $fname; ?>" /></td>
<td width="272">*<?php echo $fname_err; ?></td>
</tr>
<tr style="<?php echo $errorsurname_css; ?>">
<td>Surname</td>
<td><input type="text" name="surname" value="<?php echo $surname; ?>" /></td>
<td>*<?php echo $surname_err; ?></td>
</tr>
<tr style="<?php echo $errormidname_css; ?>">
<td>Middle Name</td>
<td><input type="text" name="middlename" value="<?php echo $middlename; ?>" /></td>
<td>*<?php echo $middlename_err; ?></td>
</tr>
<tr style="<?php echo $errormidname_css; ?>">
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Submit" /></td>
<td>&nbsp;</td>
</tr>
</table>
</form>

我想将 css 放入 Jquery 消息中,但我不知道该怎么做,有人可以帮助我吗?非常感谢,谢谢:)

最佳答案

您可以使用高亮/取消高亮方法

$("#register-form").validate({
rules: {
fname: "required",
surname: "required",
middlename: "required",
},
messages: {
fname: "Please enter your name",
surname: "Please specify your surname",
middlename: "Please specify your surname",

},
highlight: function (element, errorClass, validClass) {
$(element).closest('tr').addClass(errorClass).removeClass(validClass);
},
unhighlight: function (element, errorClass, validClass) {
$(element).closest('tr').addClass(validClass).removeClass(errorClass);
},
submitHandler: function (form) {
form.submit();
}
});

然后

.error {
color: red;
}

演示:Fiddle

关于jquery - 如果发现错误如何突出显示表行 - Jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21215351/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com