我正在尝试使用 jquery 验证注册表单。出错时,我希望文本框颜色更改为红色。但是当用户开始在文本框中书写时,颜色应该从红色更改为默认颜色。我可以在出错时将颜色更改为红色。但是当用户再次开始在文本框中书写时,颜色仍然是红色。这是我试过的示例代码。
<script type="text/javascript">
$(document).ready(function () {
$('#signup_form').validate({ // initialize the plugin
rules: {
firstName: {
required: true,
},
mobile: {
required:true,
number: true,
minlength:10
},
},
messages: {
firstName: "Enter Name",
mobile: {
required: "Enter Mobile No",
number:"Enter valid mobile no",
minlength: "Enter 10 digit mobile no"
},
},
errorPlacement: function(error, element) {
if (element.attr("name") == "firstName") {
$('#firstName').css('border-color', 'red');
$("#fname").html(error);
}
if (element.attr("name") == "mobile") {
$('#phone').css('border-color', 'red');
$("#mobile").html(error);
}
},
errorElement : "i"
});
});
</script>
最佳答案
$('#TextBox').keyup(function(){
$(this).css('color', '#fff');
})
keyup 事件应该处理它
关于jquery - 更改文本框的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28870284/