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>
  • 相关阅读:
    Spring 签名加密+xml数据交互
    Spring 使用 RestTemplate 模拟 电商网站+支付平台
    SSM 框架搭建
    SpringMVC 登录验证实例
    四.Mybatis 动态sql语句
    三.Mybatis 多对一与一对多
    二.Mybatis 增删改查
    一.Mybatis 入门
    SSH框架搭建
    二)Spring AOP编程思想与动态代理
  • 原文地址:https://www.cnblogs.com/zhuzf/p/2432695.html
Copyright © 2011-2022 走看看