Jquery判断其中任意一个文本框的值是否被修改

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="zzp">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
  <style type="text/css">   
    input:focus,textarea:focus{
       border:1px solid #f00;
       background:#fcc;
    
    }
    .focus{
       border:1px solid #f00;
        background:#fcc;
    }

   </style>
    <script type="text/javascript" src="js/jquery-1.6.4.min.js" ></script>
    <script type="text/javascript">
       var temp;
     $(function(){
           $(":input").focus(function(){   //获得焦点
                 alert(this.id);  
                 alert("获得焦点时的值是:"+$(this).val());  
                 temp=$.trim($(this).val());
                 alert(temp);
                $(this).addClass("focus");   //添加样式

           }).blur(function(){ //失去焦点
               $(this).removeClass("focus"); //移除样式
               alert("失去焦点时的值是:"+$(this).val());  
               var lastValue = $.trim($(this).val());  

               if(temp != lastValue && null !=lastValue && "" !=lastValue)
               {
                   alert("值改变了!");
               }
              
               else{
                  alert("值没有变!");
               }
               /**     */    

           });
    
     });
    
    </script>


 </head>
 <body>
    <form action="#" method="post" id="reFrom">
      <fieldset>
         <legend>个人信息</legend>
         <div>
           <label>名称:</label>
           <input id="username" type="text" value="admin">
         </div>
         <div>
           <label>密码:</label>
           <input id="pass" type="text" value="123456">
         </div>
         <div>
           <label>性别:</label>
           <input id="sex" name="sex" type="radio" value="1" checked="checked">男
           <input id="sex" name="sex" type="radio" value="2">女
         </div>
          <div>
           <label>详细信息:</label>
           <input id="msg" type="text" value="获取值">
         </div>
      
      
      </fieldset>
    
    
    </form>
 </body>
</html>

转载于:https://www.cnblogs.com/zengzhanping/p/4353810.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值