2013-05-26 38 views
2

我有這樣的功能:jQuery文檔字符串輸入框

function msj(str) { 
// display = document.getElementById("txt"); // DOM 
// nodo = document.createTextNode(str); 
// display.replaceChild(nodo,display.firstChild); 
$("#txt").html(str); // jQuery 
} 

此處顯示消息:

<div id="txt">Guess the number between 1 and 10</div> 

然後,我要顯示的消息轉換爲輸入文本形式。任何人都知道如何做到這一點?

非常感謝。

+1

我知道了!但直到你告訴我們[你試過的東西](http://whathaveyoutried.com/) –

回答

3

嘗試

<input type="text" id="txt" /> 

function msj(str) { 
    $("#txt").val(str); // jQuery 
} 
+0

非常感謝您的幫助! – user2421425

0

假設你有id=input-txt輸入的文本元素,那麼你可以做

$("#input-txt").val(str); 
+0

謝謝你的幫助! – user2421425