我想 1)刪除默認的文本在一個文本,當用戶專注於它。 2)如果他沒有輸入任何東西並點擊,則應該重新插入默認文本。的jQuery的.html()。長度不返回正確的值
我的代碼如下處理案例#1,但在Chrome和Safari(但不是Firefox)中案例#2失敗。 當我輸入文本(所以$(this).html()。length> 0),然後點擊,jQuery不正確地確定$(this).html()。length == 0,所以它刪除輸入的文本並重新插入默認文本。
jQuery(document).ready(function inputHide(){
$('textarea').each(function(){
var this_area = $(this);
var this_area_val;
this_area_val = this_area.html();
this_area.focus(function(){
if(this_area.html() == this_area_val){
this_area.html('');
}
}).blur(function(){
if(this_area.html().length == 0){
this_area.html(this_area_val);
}
});
});
感謝您的幫助。
天才。我不知道'defaultValue'屬性,但是這允許我將'textarea,input:text,input:password'個案組合成一個jQuery語句。光滑! – JMan 2010-10-07 19:24:02