Angular JS的Placeholder功能在IE8/9浏览器中不可用

附上如下代码可正常工作:

    .directive('placeholder', function($timeout){
        var i = document.createElement('input');
        if ('placeholder' in i) {
            return {}
        }
        return {
            link: function(scope, elm, attrs){
                if (attrs.type === 'password') {
                    return;
                }
                $timeout(function(){
                    elm.val(attrs.placeholder);
                    elm.bind('focus', function(){
                        if (elm.val() == attrs.placeholder) {
                            elm.val('');
                        }
                    }).bind('blur', function(){
                        if (elm.val() == '') {
                            elm.val(attrs.placeholder);
                        }
                    });
                });
            }
        }
    });

  

原文地址:https://www.cnblogs.com/chrischeng/p/3546440.html