zoukankan      html  css  js  c++  java
  • 适配 placeholder,jquery版

    <!doctype html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>适配placeholder </title>
    </head>
    <body>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script> 
     /**
      + ---------------------------------------- +
      + 适配placeholder
      + Author: zzf
      + Date: 2012-4-5
      + ---------------------------------------- +
     **/
     jQuery.fn.placeholder = function () {
         return this.each(function(){
             if ('placeholder' in document.createElement(this.tagName)) return;
             var self = this,
                 placeholder = self.getAttribute('placeholder') || self.getAttribute('value'),
                 el = jQuery(self);
             //如果placeholder和value属性同时存在,以placeholder为准
             if (self.value === '' || self.value !== placeholder) {
                 self.value = placeholder;
             }
     
             el.bind({
                 'focus':function (){
                     this.value === placeholder && (this.value = '');
                 },
                 'blur':function (){
                     this.value === '' && (this.value = placeholder);
                 }
             })
         })
     };
    
    //测试
     $(document).ready(function (){
         $('#test-wrap').find('.demo').placeholder();
    })
    </script>
    <div id="test-wrap"> 
        <input id="" class="demo" type="text" name=""  placeholder="text的placeholder" /> <br /><br />
        <textarea id="" class="demo" name="" rows="" cols="20" placeholder="textarea的placeholder"  ></textarea><br />
    </div>
    
    </body>
    </html>
  • 相关阅读:
    Django ajax 实现 loading 效果
    K8S service 简单介绍
    K8S Pod 生命周期 (二)
    异度之刃 Xenoblade 后感
    Nested Prefab Mode 嵌套预制体 保存问题 Dirty
    GIT速成
    Surface电池阈值
    如何删除通知栏无效图标(重置任务栏通知区域)
    Mouse For Winpad
    Re:LieF ~親愛なるあなたへ~ 后感
  • 原文地址:https://www.cnblogs.com/zhuzf/p/2432695.html
Copyright © 2011-2022 走看看