IE9以下 placeholder兼容

谁说胖子不能爱 提交于 2019-11-28 06:12:49
//input placeholder兼容!(function ($, doc, win) {    $.fn.placeholder = function () {        var i = doc.createElement('input'),            placeholdersupport = 'placeholder' in i;        if (!placeholdersupport) {            var inputs = $(this);            inputs.each(function () {                var input = $(this),                    text = input.attr('placeholder'),                    pdl = 0,                    height = input.outerHeight(),                    width = input.outerWidth(),                    placeholder = $('<span class="phTips_tadllj">' + text + '</span>');                try {                    pdl = input.css('padding-left').match(/\d*/i)[0] * 1;                } catch (e) {                    pdl = 5;                }                placeholder.css({ 'margin-left': -(width - pdl), 'height': height, 'line-height': height + "px", 'position': 'absolute', 'color': "#999", 'font-size': "14px", "z-index": "100" });                placeholder.click(function () {                    //placeholder.css({display:'none'});                    input.focus();                });                if ($.trim(input.val()).length > 0) {                    placeholder.css({ display: 'none' });                } else {                    placeholder.css({ display: 'inline' });                }                placeholder.insertAfter(input);                input.on("focus", function (e) {                    placeholder.css({ display: 'none' });                }).on("blur", function (e) {                    var _this = $(this);                    if ($.trim(_this.val()).length > 0) {                        placeholder.css({ display: 'none' });                    }                    else {                        placeholder.css({ display: 'inline' });                    }                });                // .keyup(function(e){                //     if($(this).val() != ""){                //         placeholder.css({display:'none'});                //     }else{                //         placeholder.css({display:'inline'});                //     }                // })            });        }        return this;    };    var isIe = false;    if (navigator.userAgent.indexOf("MSIE") > 0) {        if (!$.support.leadingWhitespace || navigator.userAgent.indexOf("MSIE 9.0") > 0) {//IE9以下不让登陆            isIe = true;        }    }    if (isIe) {        $('input[placeholder]').placeholder();    }})(jQuery, document, window);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!