admin管理员组

文章数量:1558058

/**
 * 函数:实现ie浏览器对placeholder的兼容
 * 输入:
 * 输出:
**/
function compatiblePlaceholder(){
    var isPlaceholder = 'placeholder' in document.createElement('input');
    if (!isPlaceholder) {
        $("input[placeholder]").each(function() {
            var text = $(this).attr("placeholder");
            var $span = $('<span class="place_holder">'+ text +'</span>');
            $(this).before($span);
            var $that = $(this);
            $span.on("click focus",function() {
                $that.click();
            });
            $(this).click(function() {
                $(this).focus();
                $span.hide();
            });
            $(this).blur(function(){
                $span.show();
            });
        });
        $(".two_ph").each(function() {
            $(this).find(".place_holder").eq(1).addClass("for_ben_rate");
        });
    }
}

老版本ie浏览器不支持placeholder功能,为了实现该功能,有多个思路,以上是本人提供的一个思路,利用一个span标签来模拟placeholder。

本文标签: 浏览器Placeholder