首页 > 代码库 > ie中placeholder属性不支持,js解决

ie中placeholder属性不支持,js解决

ie中placeholder属性不支持,js的解决方法:

//placeholder属性在ie下兼容
            function placeholder ( pEle , con ) {
                var pEle = pEle
                if( pEle.find("input,textarea").val() == "" ){
                    pEle.append("<i class=‘placeholder_ie‘>"+con+"</i>");
                }
                pEle.click(function () {
                    $(this).find(".placeholder_ie").css("display","none");
                    $(this).find("input,textarea").focus();
                })
                pEle.find("input,textarea").blur(function () {
                    if( pEle.find("input,textarea").val() == "" ){
                        pEle.find(".placeholder_ie").css("display","inline-block");
                    }
                })
            }
            // ie浏览器
            if( navigator.appName == "Microsoft Internet Explorer" ){
                placeholder( $(".header_box .serach_content").eq(0) , "search..." );
                placeholder( $(".news_product .search_website>p").eq(0) , "深圳" );
            }

css:

/*输入框ie下placeholder样式*/
.placeholder_ie{
    display: inline-block;
    width:100%;
    height:26px;
    position: absolute;
    left:-42px;
    top:0;
    line-height: 26px;
    font-size: 14px;
    padding:0 10px;
    color:#989898;
}

 

ie中placeholder属性不支持,js解决