• input默认值设置


    由于项目需求,简单地写了一个input默认值设置

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <title>input默认值设置</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript">
    $(function() {
        //集体调用
    	$(".form input").each(function(){
    		$(this).setDefauleValue();
    	});
    	//单个调用
    	$("#key").setDefauleValue();
    })
    
    //设置input,textarea默认值
    $.fn.setDefauleValue = function() {
        var defauleValue = $(this).val();
    	$(this).val(defauleValue).css("color","#999");
    
        return this.each(function() {		
            $(this).focus(function() {
                if ($(this).val() == defauleValue) {
                    $(this).val("").css("color","#000");//输入值的颜色
                }
            }).blur(function() {
                if ($(this).val() == "") {
                    $(this).val(defauleValue).css("color","#999");//默认值的颜色
                }
            });
        });
    }
    </script>
    </head>
    
    <body>
    <form class="form">
      <input type="text" size="30" value="输入昵称">
      <br>
      <input type="text" size="30" value="输入姓名">
    </form>
    <br>
    <br>
    <br>
    <input type="text" size="30" id="key" value="输入学员ID、姓名、昵称进行查找">
    </body>
    </html>
    

  • 相关阅读:
    牛客网分糖果
    【bzoj3717】[PA2014]Pakowanie 状压dp
    【bzoj1042】[HAOI2008]硬币购物 背包dp+容斥原理
    [POI2007]堆积木Klo
    【bzoj5018】[Snoi2017]英雄联盟 背包dp
    BZOJ 1492 [NOI2007]
    bzoj 2741 [FOTILE模拟赛] L
    bzoj 1486 最小圈
    计数
    cf 700
  • 原文地址:https://www.cnblogs.com/mofish/p/2167196.html
Copyright © 2020-2023  润新知