惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
雷峰网
雷峰网
Last Week in AI
Last Week in AI
T
Tailwind CSS Blog
V
Visual Studio Blog
Jina AI
Jina AI
博客园 - 司徒正美
The Cloudflare Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
小众软件
小众软件
V
V2EX
Apple Machine Learning Research
Apple Machine Learning Research
美团技术团队
博客园 - 【当耐特】
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
WordPress大学
WordPress大学
爱范儿
爱范儿
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏

博客园 - 码 头

实测有效:Win11右键默认显示更多设置教程 netcore 并发锁 多线程中使用SemaphoreSlim HTML转义字符大全 .Net Core后台任务启停(BackgroundService) 常见的JavaScript的循环处理数据方法 Linux下.NET Core进程守护设置,解决SSH关闭后.NET Core服务无法访问的问题 记录 IIS 部署vue 项目步骤 AspNetCoreApi 跨域处理(CORS ) .NET CORE 使用Session报错:Session has not been configured for this application or request 小豆苗疫苗辅助搜索 日期函数(sql) 图片javascript缩小 c# DESEncrypt 加密、解密算法 汉字编码问题转换 二分法算法 MVC拦截器记录操作用户日志 最全的Resharper快捷键汇总 如何将数据库中的表导入到PowerDesigner中 sql脚本查询日期时间段日期
修复IE9.0下PlaceHolder 属性问题js脚本
码 头 · 2015-09-15 · via 博客园 - 码 头

在开发前端系统时候碰到这种兼容问题,以下是个人解决方案,希望能给其他人带来帮助:

var JPlaceHolder = {
    //检测
    _check: function () {
        return 'placeholder' in document.createElement('input');
    },
    //初始化
    init: function () {
        if (!this._check()) {
            this.fix();
        }
    },
    //修复
    fix: function () {        
        jQuery(':input[placeholder]').each(function (index, element) {
            var self = $(this), txt = self.attr('placeholder'), atrValue = self.attr('type');

            //密码文本框
            if (atrValue == "password") {
                self.attr("type", "text");
                self.attr("pwd", "true");
            } else {
                self.attr("pwd", "false");
            }

            self.focusin(function (e) {
                var atrpwd = self.attr('pwd');
                if (atrpwd == "true") {
                    self.attr("type", "password");
                } else {
                    self.attr("type", "text");
                }
                self.val("");
            }).focusout(function (e) {
                if (!self.val()) {
                    self.attr("type", "text");
                    self.val(txt);
                }
            });
            if (self.val().length > 0) {
                self.val("");
            }
            else {
                self.val(txt);

            }

        });
    }
};
//执行
jQuery(function () {
    JPlaceHolder.init();
});