国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery表單獲取和失去焦點輸入框提示效果的實例代碼

2019-11-20 22:28:27
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

  $("#focus .input_txt").each(function(){
  var thisVal=$(this).val();
  //判斷文本框的值是否為空,有值的情況就隱藏提示語,沒有值就顯示
  if(thisVal!=""){
  $(this).siblings("span").hide();
  }else{
  $(this).siblings("span").show();
  }
  //聚焦型輸入框驗證 
  $(this).focus(function(){
  $(this).siblings("span").hide();
  }).blur(function(){
  var val=$(this).val();
  if(val!=""){
  $(this).siblings("span").hide();
  }else{
  $(this).siblings("span").show();
  } 
  });
  })
  $("#keydown .input_txt").each(function(){
  var thisVal=$(this).val();
  //判斷文本框的值是否為空,有值的情況就隱藏提示語,沒有值就顯示
  if(thisVal!=""){
  $(this).siblings("span").hide();
  }else{
  $(this).siblings("span").show();
  }
  $(this).keyup(function(){
  var val=$(this).val();
  $(this).siblings("span").hide();
  }).blur(function(){
  var val=$(this).val();
  if(val!=""){
  $(this).siblings("span").hide();
  }else{
  $(this).siblings("span").show();
  }
  })
  }) 
  })
</script>
<style type="text/css">
 form{width:400px;margin:10px auto;border:solid 1px #E0DEDE;background:#FCF9EF;
          padding:30px;box-shadow:0 1px 10px rgba(0,0,0,0.1) inset;}
 label{display:block;height:40px;position:relative;margin:20px 0;}
 span{position:absolute;float:left;line-height:40px;left:10px;color:#BCBCBC;cursor:text;}
 .input_txt{width:398px;border:solid 1px #ccc;box-shadow:0 1px 10px rgba(0,0,0,0.1) inset;
          height:38px;text-indent:10px;}
 .input_txt:focus{box-shadow:0 0 4px rgba(255,153,164,0.8);border:solid 1px #B00000;}
 .border_radius{border-radius:5px;color:#B00000;}
 h2{font-family:"微軟雅黑";text-shadow:1px 1px 3px #fff;}
</style>
</head>
<body>
 <form class="border_radius" id="focus">
        <h2>聚焦型提示語消失  無效果請刷新</h2>
        <label><span>花瓣注冊郵箱</span><input type="text" class="input_txt border_radius"  />
        </label>
        <label><span>密碼</span><input type="text" class="input_txt border_radius" /></label>
    </form>
 <form class="border_radius" id="keydown">
     <h2>輸入型提示語消失</h2>
     <label><span>花瓣注冊郵箱</span><input type="text" class="input_txt border_radius"  />
       </label>
        <label><span>密碼</span><input type="text" class="input_txt border_radius" /></label>
    </form>
</body>
</html>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 灵宝市| 原阳县| 莱州市| 广宗县| 义乌市| 马边| 曲水县| 宁乡县| 松潘县| 固镇县| 工布江达县| 长岛县| 厦门市| 阿勒泰市| 武夷山市| 随州市| 枝江市| 汝阳县| 西乌珠穆沁旗| 唐海县| 独山县| 阳新县| 河北省| 布尔津县| 平顺县| 日喀则市| 湟源县| 长宁区| 菏泽市| 都匀市| 大邑县| 商南县| 安新县| 松原市| 阜南县| 宝丰县| 绥德县| 陵川县| 祁阳县| 阿荣旗| 和平县|