关于input 属性placeholder 在IE9下兼容

今天分享下同事关于input 属性placeholder 在IE9下不兼容的解决方案,小弟不是很懂,希望有看完的大佬说说你们的理解

<script src="http://www.jq22.com/jquery/1.8.3/jquery.min.js"></script>
<script>
(function($){
    $.fn.placeholder = function(options){
        var opts = $.extend({}, $.fn.placeholder.defaults, options);
        var isIE = document.all ? true : false;
        return this.each(function(){
            var _this = this,
                placeholderValue =_this.getAttribute("placeholder"); //缓存默认的placeholder值
            if(isIE){
                _this.setAttribute("value",placeholderValue);
                _this.onfocus = function(){
                    $.trim(_this.value) == placeholderValue ? _this.value = "" : ‘‘;
                };
                _this.onblur = function(){
                    $.trim(_this.value) == "" ? _this.value = placeholderValue : ‘‘;
                };
            }
        });
    };
})(jQuery);
$("input").placeholder();
</script>

求大佬看完后分析下,或等我改天询问到再分享给大伙。

原文地址:https://www.cnblogs.com/smile-xin/p/11517236.html

时间: 2024-08-24 03:43:29

关于input 属性placeholder 在IE9下兼容的相关文章

HTML5的placeHolder在IE9下workaround引发的Bug(按下葫芦起了瓢)

详见StackOverFlow的:Simple jQuery form Validation: Checking for empty .val() failing in ie9 due to placeholder polyfill 由于引入ployfill,导致在IE9下,value成了placeholder的值,因此如果要做表单验证,除了判断表单元素的值为空,还要谨防value===placeholder的情况.

兼容IE8以下浏览器input表单属性placeholder不能智能提示功能,以及使用jquery.validate.js表单验证插件的问题处理

当前很多表单提示使用了表单属性placeholder,可这属性不兼容IE8以下的浏览器,我自己写了一个兼容处理js // 兼容IE8以下浏览器input不能智能提示功能 if(navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion.match(/7./i)=="7." || navigator.appVersion.match(/8./i)=="

在safari下input的placeholder设置行高失效

在项目中遇到input的placeholder在safari下设置行高失效的问题,亲测 input{ width:250px; height:30px; line-height:30px; font-size:14px; padding:0px 0px 0px 30px; [;line-height:1;color:#f00;] } 单独针对Safari来写hack 原文地址:https://www.cnblogs.com/guoliping/p/9798703.html

再谈multistage text input(中文输入法)下UITextView的内容长度限制

之前写过一篇<如何更好地限制一个UITextField的输入长度>,在文章最后得到的结论是可以直接使用 UIKIT_EXTERN NSString *const UITextFieldTextDidChangeNotification; 进行监听,截断超出maxLength的部分. 所以后来我在处理UITextView的内容长度时,也直接参考这个方法: [[NSNotificationCenter defaultCenter] addObserver:self selector:@select

placeholder 不支持进行兼容处理

;(function () { //全局ajax处理 $.ajaxSetup({ complete: function (jqXHR) {}, data: { }, error: function (jqXHR, textStatus, errorThrown) { //请求失败处理 } }); if ($.browser.msie) { //ie 都不缓存 $.ajaxSetup({ cache: false }); } //不支持placeholder浏览器下对placeholder进行处理

IE9下JQuery发送ajax请求失效

最近在做项目的时候,测试PC端网页,在IE9下会失效,不能正常的发送POST请求,经过仔细的排查,发现是IE9下JQuery发送ajax存在跨域问题. 目前有两种解决方案:   解决方案一: 设置浏览器安全属性,启用[通过域访问数据源]选项,如下图所示:    解决方案二:  调用ajax方法时,设置crossDomain为true,如下图所示: <!DOCTYPE html> <html> <head> <title>jQuery CORS in IE7

html5 placeholder ie10以下不兼容

/*html5 placeholder ie10以下不兼容 加上这个jquery代码可以解决兼容*/ $(function(){ if(!placeholderSupport()){ // 判断浏览器是否支持 placeholder $('[placeholder]').focus(function() { var input = $(this); if (input.val() == input.attr('placeholder')) { input.val(''); input.remov

记录:asp.net mvc 中 使用 jquery 实现html5 实现placeholder 密码框 提示兼容password IE6

@{ViewBag.Title = "完美结合";} <script>var G_start_time = new Date;</script> <!--[if (lt IE 8.0)]><link type="text/css" rel="stylesheet" href="@Url.Content("~/Content/login/css/index.src_datauri.css

vue-cli 在IE下兼容设置

最近我们的项目选择用vue来做开发,在这个过程IE兼容性 首先我们按照步骤来安装vue-cli 创建项目运行 npm install npm run dev 然后我们在ie9下打开发现没有用但是vue官网告诉我们他是兼容ie9的 官网地址:https://github.com/vuejs/vue 下图是错误提示ie9:  然后就找资料查文档,总算给我找到了. 要实现其实很简单,只需要我们下载一个babel-polyfill, npm install babel-polyfill --save-d