zoukankan      html  css  js  c++  java
  • placeholder不显示的解决办法(支持ie8以上)

    //   兼容ie9的placeholder
    function isPlaceholder(){
        var input = document.createElement('input');
        return 'placeholder' in input;
    }
    if (!isPlaceholder()) {//不支持placeholder 用jquery来完成
        $(document).ready(function() {
            if(!isPlaceholder()){
                $("input").not("input[type='password']").each(//把input绑定事件 排除password框
                        function(){
                            if($(this).val()=="" && $(this).attr("placeholder")!=""){
                                $(this).val($(this).attr("placeholder"));
                                $(this).focus(function(){
                                    if($(this).val()==$(this).attr("placeholder")) $(this).val("");
                                });
                                $(this).blur(function(){
                                    if($(this).val()=="") $(this).val($(this).attr("placeholder"));
                                });
                            }
                        });
                //对password框的特殊处理1.创建一个text框 2获取焦点和失去焦点的时候切换
                $("input[type='password']").each(
                        function() {
                            var pwdField    = $(this);
                            var pwdVal      = pwdField.attr('placeholder');
                            pwdField.after('<input  class="login-input" type="text" value='+pwdVal+' autocomplete="off" />');
                            var pwdPlaceholder = $(this).siblings('.login-input');
                            pwdPlaceholder.show();
                            pwdField.hide();
    
                            pwdPlaceholder.focus(function(){
                                pwdPlaceholder.hide();
                                pwdField.show();
                                pwdField.focus();
                            });
    
                            pwdField.blur(function(){
                                if(pwdField.val() == '') {
                                    pwdPlaceholder.show();
                                    pwdField.hide();
                                }
                            });
                        })
            }
        });
    }

    方法 二:

    jQuery('[placeholder]').focus(function() {
      var input = jQuery(this);
      if (input.val() == input.attr('placeholder')) {
        input.val('');
        input.removeClass('placeholder');
      }
    }).blur(function() {
      var input = jQuery(this);
      if (input.val() == '' || input.val() == input.attr('placeholder')) {
        input.addClass('placeholder');
        input.val(input.attr('placeholder'));
      }
    }).blur().parents('form').submit(function() {
      jQuery(this).find('[placeholder]').each(function() {
        var input = jQuery(this);
        if (input.val() == input.attr('placeholder')) {
          input.val('');
        }
      })
    });
  • 相关阅读:
    IIS: 必须输入密码手动设置密码同步后
    IIS操作控制类
    SQL对IP地址进行拆分
    HTTP_REFERER的工作方式[转贴]
    如何知道同服务器上都有哪些网站?
    简单判断临时表是否存在
    .NET 3.5 SP 1发布了
    Log Parser很好很强大的IIS日志分析工具
    遍历Request.ServerVariables
    06复杂查询(多数据库表)
  • 原文地址:https://www.cnblogs.com/fyy-888/p/5387779.html
Copyright © 2011-2022 走看看