解決IE下輸入框不支持placeholder屬性
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/><!--important-->
<meta charset="utf-8"/>
<title>解決IE下不支持placeholder屬性</title>
<script src="http://www.jq22.com/jquery/1.8.3/jquery.min.js"></script>
<style type="text/css">
.text{width: 200px;padding: 10px;}
</style>
<script type="text/javascript">
;(function($){
$.fn.placeholder = function(options){
var opts = $.extend({}, $.fn.placeholder.defaults, options);
var isIE = document.all ? true : false;
return this.each(function(){
var _this = this,
placeholderValue =_this.getAttribute("placeholder"); //緩存默認的placeholder值
if(isIE){
_this.setAttribute("value",placeholderValue);
_this.onfocus = function(){
$.trim(_this.value) == placeholderValue ? _this.value = "" : '';
};
_this.onblur = function(){
$.trim(_this.value) == "" ? _this.value = placeholderValue : '';
};
}
});
};
})(jQuery);
</script>
</head>
<body>
<input placeholder="請輸入用密碼" type="password" class="text"/>
<input placeholder="請輸入用戶名" type="text" class="text" />
<script type="text/javascript">
$("input").placeholder();
</script>
</body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.