jQuery背景颜色在焦点和模糊上的变化 [英] jquery background-color change on focus and blur

查看:116
本文介绍了jQuery背景颜色在焦点和模糊上的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:我有一个带有三个文本输入字段的表单,并且当其中一个字段具有焦点时,我想更改背景颜色,而在失去焦点时将其设置回去.我想出了以下代码:

I have the following problem: I have a form with three text input fields, and I want to change the background-color when one of the fields has focus, and get it set back when it loses focus. I have come up with the following code:

HTML(简体):

<form>
<input class="calc_input" type="text" name="start_date" id="start_date" />
<input class="calc_input" type="text" name="end_date" id="end_date" />
<input class="calc_input" size="8" type="text" name="leap_year" id="leap_year" />
</form>

jQuery

$(document).ready(function() {
    $('input:text').focus(
    function(){
        $(this).css({'background-color' : '#FFFFEEE'});
    });

    $('input:text').blur(
    function(){
        $(this).css({'background-color' : '#DFD8D1'});
    });
});

谢谢

推荐答案

#FFFFEEE不是正确的颜色代码.尝试使用#FFFFEE.

#FFFFEEE is not a correct color code. Try with #FFFFEE instead.

这篇关于jQuery背景颜色在焦点和模糊上的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆