ie8浏览器把placeholder当作value

2016-09-28  本文已影响0人  杜乡的AGG

引入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())
    });
上一篇 下一篇

猜你喜欢

热点阅读