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>
  • 相关阅读:
    [转]用asp.net实现远程获取其他网站页面指定内容
    Occupation career planning
    【原创】Self-Contained Container(自包含容器)
    Kindle 转换器
    Win32 多线程学习笔记
    OC学习心得【适合初学者】
    OC-通讯录
    植物大战僵尸
    三、属性和点语法
    二十、函数指针高级(动态调用)
  • 原文地址:https://www.cnblogs.com/zhuzf/p/2432695.html
Copyright © 2011-2022 走看看