zoukankan      html  css  js  c++  java
  • 当浏览器不支持placeholder,所执行的函数

    $(function(){
    
    //判断浏览器是否支持placeholder属性
    
    supportPlaceholder='placeholder'in document.createElement('input'),
    
    placeholder=function(input){
    
    var text = input.attr('placeholder'),
    
    defaultValue = input.defaultValue;
    
    if(!defaultValue){
    
    input.val(text).addClass("phcolor");
    
    }
    
    input.focus(function(){
    
    if(input.val() == text){
    
    $(this).val("");
    
    }
    
    });
    
    input.blur(function(){
    
    if(input.val() == ""){
    
    $(this).val(text).addClass("phcolor");
    
    }
    
    });
    
    //输入的字符不为灰色
    
    input.keydown(function(){
    
    $(this).removeClass("phcolor");
    
    });
    
    };
    
    //当浏览器不支持placeholder属性时,调用placeholder函数
    
    if(!supportPlaceholder){
    
    $('input').each(function(){
    
    text = $(this).attr("placeholder");
    
    if($(this).attr("type") == "text"){
    
    placeholder($(this));
    
    }
    
    });
    
    }
    
    });
  • 相关阅读:
    Jmeter与LoadRunner 测试Java项目的坑
    关于<forEach>的<if>混合使用显示数据
    无题。省
    无题。思
    767A Snacktower
    喵哈哈村的括号序列

    队列
    优先队列
    768A Oath of the Night's Watch
  • 原文地址:https://www.cnblogs.com/wangxue420/p/6265691.html
Copyright © 2011-2022 走看看