首页 > 其他 > 详细

placeholder 不支持ie8

时间:2018-10-30 00:44:12      阅读:199      评论:0      收藏:0      [点我收藏+]
        function placeholder(el){
            function isPlaceHolder(){
                var textarea = document.createElement("textarea");
                return "placeholder" in textarea;
            }
        debugger;
        var $el = $(el);
        //在不支持placeHolder属性的情况下
        if(isPlaceHolder() == false && !('placeholder' in document.createElement('textarea'))){
            $('textarea[placeholder]').each(function(){
                var that = $(this);
                text = that.attr('placeholder');
                
                if(that.val()===""){
                    that.val(text).addClass('placeholder');
                }
                
                //获得光标焦点后,输入框的内容清空
                that.focus(function(){
                    if($el.html() == text){
                        $el.html("");
                    }
                    if(that.val() == text){
                        that.val("").removeClass('placeholder');
                    }
                }).blur(function(){
                    //光标焦点离开输入框时,给输入框添加提示内容
                    if(that.val() === ""){
                        
                        that.val(text).addClass('placeholder');
                    }
                })
            })
        }

    }
</script/>

-->

placeholder 不支持ie8

原文:https://www.cnblogs.com/sidekick/p/9874179.html

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