2009-07-30 162 views
0

我想單擊文本框來顯示幫助文本。 例如:如果我點擊文本框它應該幫助我們,說什麼類型:在這裏輸入的用戶名使用jquery在單擊文本框中顯示幫助文本

我曾嘗試如下的代碼,但文本「輸入用戶名」的淡出,我想要顯示文字,直到焦點改變爲另一個文本框。

請爲此類型建議一些代碼。

<input type = "text"/><span>Enter username</span> 
<input type = "text"/><span>Enter password</span>  


$(document).ready(function(){ 
    $("input").focus(function() { 
     $(this).next("span").css('display','inline').fadeOut(1000); 
    }); 
}); 

回答

4

類似下面應該這樣做

$(function(){ 
    $("input") 
     .focus(function() { 
      $(this).next("span").fadeIn(1000); 
     }) 
     .blur(function() { 
      $(this).next("span").fadeOut(1000); 
     }); 
}); 

這裏是一個Working Demo

+0

我的工作演示非常棒職業夥伴 – 2009-07-30 12:19:55

1

我不知道爲什麼你操縱CSS display屬性以及使用淡入/ fadeOut:

$(document).ready(function(){ 
    $("input").focus(function() { 
     $(this).next("span").fadeIn(1000); 
    }).blur(function() { 
     $(this).next("span").fadeOut(1000); 
    }); 
}); 
相關問題