我想更改包含我的输入字段的DIV的背景颜色。当您在输入中输入数据时,代码正常工作,背景颜色变为红色。但是,当我返回并清除输入字段留空的数据时,背景不会回到原来的颜色。需要脚本通过输入更改div背景..不工作
我需要DIV的背景颜色在空白时恢复到原来的颜色。
我在做什么错?
这里是我的代码:
<script>
$(document).ready(function(){
$("#id").keypress(function() {
if($("#id").val().length > 0) $("#in").css("background-color", "red");
else {
if($("#id").val().length = 0) $("#in").css("background-color", "grey");
}
});
});
</script>