JQuery html字符串输入框

时间:2013-05-26 01:52:26

标签: jquery html string forms input

我有这个功能:

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>

然后,我想将消息显示为输入文本格式。谁知道怎么做?

非常感谢。

3 个答案:

答案 0 :(得分:3)

尝试

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

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

答案 1 :(得分:0)

假设您有一个带id=input-txt的输入文本元素,那么您可以

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

答案 2 :(得分:0)

的jQuery

function msj(str){
  $("#txt").val(str);
}

HTML

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

好吧,也许这对于回答你问题的相关链接来说有点过分,但他们都会回答你的问题。