其實想作聚焦時提示文字不消失,光標在提示語前面,就像正常的placeholder屬性,可是setSelectionRance()方法不是很好用,後面學習以後再製做javascript
<script type="text/javascript">
(function($,win,doc){
$.fn.extend({css
textareaPlaceholer:function(){
var browser=navigator.appName
var b_version=navigator.appVersion
var version=b_version.split(";");
var trim_Version=version[1].replace(/[ ]/g,"");
if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE8.0" || browser=="Microsoft Internet Explorer" && trim_Version=="MSIE9.0") java
//若是是IE8 或者 IE9
{
var placeholder = $(this).attr("placeholder");
if (placeholder) {
if ($(this).val().length <= 0) {
$(this).val(placeholder).css("color","#999");
$(this).focus(function(){
if ($(this).val() == placeholder) {
$(this).val("").css("color","#333");
}
//監控刪除按鈕
$(this).bind('keyup',function(e){
if (e.keyCode == 8) {
if ($(this).val().length == 0) {
$(this).val(placeholder).css("color","#999").blur();
}
}
});
}).blur(function(){
if ($(this).val().length <= 0) {
$(this).val(placeholder).css("color","#999");
}
});app
}
}學習
}
}
}); this
})(jQuery,window,document);ip
$("#textarea").textareaPlaceholer();it