美文网首页
ie8浏览器把placeholder当作value

ie8浏览器把placeholder当作value

作者: 杜乡的AGG | 来源:发表于2016-09-28 14:53 被阅读0次

引入jquery.placeholder.js后,ie8可以支持placeholder,但是在ie8下,如果input没有输入值的时候,浏览器会把placeholder的值当作value的值传回后台

解决方案

 $.fn.pVal = function(){
        var $this = $(this),
            val = $this.eq(0).val();
        if(val == $this.attr('placeholder'))
            return '';
        else
            return val;
    }
    $(function(){
        alert($('input').val())
        alert($('input').pVal())
    });

相关文章