首页 > 其他 > 详细

让IE低版本浏览器也支持placeholder属性

时间:2014-12-22 12:47:02      阅读:244      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>让IE低版本浏览器也支持placeholder属性</title>
    <script type="text/javascript"  src="http://ajax.microsoft.com/ajax/jquery/jquery-1.11.1.min.js"></script>
    <script type="text/javascript">
        $(function () {
            if (/MSIE\s(\d+)/.test(navigator.userAgent) && navigator.userAgent.match(/MSIE\s(\d+)/)[1] < 10) {
                $(‘[placeholder]‘).each(function () {
                    var pla = $(this).attr(‘placeholder‘);
                    $(this).focus(function () {
                        if ($(this).val() == pla) {
                            $(this).val(‘‘);
                        }
                    }).blur(function () {
                        if ($(this).val() == ‘‘) {
                            $(this).val(pla);
                        }
                    });
                    $(this).trigger(‘blur‘);//此处利用blur事件,为了业务需求。防止页面上查询后,文本框需要保留搜索的关键被placeholder代替
                });
            }
        });
    </script>
</head>
<body>
    <input type="text" placeholder="请输入关键字" />
</body>
</html>

让IE低版本浏览器也支持placeholder属性

原文:http://www.cnblogs.com/liaohaihui/p/4177868.html

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