//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);
时间: 2025-01-15 05:30:47