今天是我第二次,自己写JQ代码,求一个点击后文本框变色代码,再点击恢复颜色。想学习下各位大写如何写的,谢过~~!
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function(){
$("selector").focus(function(){
$("input").css("border","red")
})
})
</script>
</head><body>
<ul>
<li>姓名:<input name="" type="text" /></li>
    <li>密码:<input name="" type="text" /></li>
    <li>网址:<input name="" type="text" /></li>
</ul>
</body>

解决方案 »

  1.   

    如果是高版本的浏览器 你可以使用css来实现。input:focus{
        border: 1px solid #F00;
    }
      

  2.   

    $("ul input").click(function(){
    $(this).parent().siblings().each(function(){
      $(this).find("input").css("background-color","");
    });
      $(this).css("background-color","red");
    });
      

  3.   

    <style>
    .bgcolor:{background-color:red}
    </style>$(function(){
    $("selector").focus(function(){
        $(this)..toggleClass('bgcolor');
    })
    })
      

  4.   

    如果是focus和blur中处理,那可以同时绑定两个事件
    $(function(){
        $("ul :input").bind({
            "focus":function(){
                $(this).css("border","1px solid red");
            },
            "blur":function(){
                $(this).css("border","1px solid black");
            }
        })
    })
    或者你定义了一个样式。
    <style type="text/css">
    .bg{border:1px solid red}
    </style>
    <script type="text/javascript">
    $(function(){
        $('#_ul :input').bind('focus blur', function() {
          $(this).toggleClass('bg');
        });})
    </script>