angular 解決placeholder兼容問題


//模擬ie不兼容問題

.directive('inputs', ['$compile', function($compile){
return {
restrict: 'ECMA',
scope: {},
link: function(scope, ele, attr) {
console.log(ele.context);
console.log(scope);
var input = document.createElement('input');
var isSupportPlaceholder = 'placeholder' in input;
if (!isSupportPlaceholder) {
var fakePlaceholder = angular.element(
'<span class="plcaeholder" style="position:absolute;margin:10px 0 0 10px;color:#666">' +attr['placeholder'] + '</span>');
fakePlaceholder.on('click', function(e){
e.stopPropagation();
ele.focus();
});
ele.before(fakePlaceholder);
scope.hasValue = function(){
return ele.val();
};
scope.$watch(scope.hasValue, function(){
if (ele.val()) {
fakePlaceholder.hide();
}
});
$compile(fakePlaceholder)(scope);
ele.on('focus', function(){
console.log(1111)
fakePlaceholder.hide();
}).on('blur', function(){
if (ele.val() === '') {
fakePlaceholder.show();
}
});
}
}
};
}]);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM