首页 > Web开发 > 详细

Html5 placeholder在ie10以下伪提示

时间:2014-11-03 12:43:29      阅读:307      评论:0      收藏:0      [点我收藏+]

大家是知道的Html5在ie10以上的版本才支持,最近用bootstrap前端开发框架搞一个网站,想在ie10以下也能提示,所以就得用js伪装下了。

首先判断浏览器是否支持placeholder

if (!(‘placeholder‘ in document.createElement(‘input‘)))

然后追加text,本来想要直接更改val值的,获得鼠标清空,但是如果需要验证他是必填项的话就不对了。所以还是追加text。

$("input").not("input[type=‘password‘]").each(//把input绑定事件 排除password框  
                 function () {
                     if ($(this).val() == "" && $(this).attr("placeholder") != undefined) {
                         $(this).after(‘<input class="‘ + $(this).attr("class") + ‘" type="text" value=‘ + $(this).attr("placeholder") + ‘ autocomplete="off" />‘);
                         //$(this).val($(this).attr("placeholder"));
                         $(this).hide(); $(this).next().show();
                         $(this).next().focus(function () {
                             $(this).prev().show();
                             $(this).prev().focus();
                             $(this).hide();
                         });
                         $(this).blur(function () {
                             if ($(this).val() == "") { $(this).hide(); $(this).next().show(); }
                         });
                     }
也许还不太完美,希望大家指出。

Html5 placeholder在ie10以下伪提示

原文:http://www.cnblogs.com/liangleiming/p/4070832.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!