2014-02-18 93 views
0

我會告訴你Fiddle link關於我的程序問題。通過Javascript輸入帶有輸入標記的內容時獲取文本

<label for="test">Username:</label> 
<input type="text" id="test"> 
<p id=""></p> 
$("#test").onclick(function(){ 
    alert('xx');     
}) 

我想實現這個功能: p標籤的實時顯示input標籤的內容,當我輸入的東西。如果你回答我,我會很開心。

謝謝。

+0

請解釋一下你的question.Didnt明白的事情 –

+0

使用的onfocus或onblur.not的onclick –

回答

1

您可以使用keyup事件,

$("#test").keyup(function(){ 
     $("#para").html(this.value) ;    
}); 

FIDDLE DEMO.

+2

你打我吧:) – Joseph

1

你可以將它連接到keyup事件這樣,它與每個按鍵更新。

試試這個http://jsfiddle.net/Z2Xwr/1/

$("#test").keyup(function(){ 
     $('#paragraph').html($(this).val());    
}) 
相關問題