我想要填充空白测验样本。我有文本框,这个文本框在测验中将为空白。我想验证此texbox值,如果是真的,我会将文本框的颜色更改为绿色,如果它不会是红色的。你知道这样的jquery样本吗?我想要客户端解决方案。谢谢
答案 0 :(得分:1)
你的问题不是很清楚。你什么时候想要改变颜色?我将假设您希望它发生在blur
事件:
$("#yourTextboxId").blur(function() {
if(!this.value) {
$(this).css({backgroundColor: "red"});
}
else {
$(this).css({backgroundColor: "green"});
}
});
答案 1 :(得分:0)
你可以这样做 -
$("#question").blur(function() {
if ($(this).val() == 'Paris') $(this).css('background-color','green');
else $(this).css('background-color','red');
});
这将对blur
事件进行验证,以便在文本框失去焦点时触发验证。您需要将验证代码更改为适合您需求的代码。