我有这个功能:
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>
然后,我想将消息显示为输入文本格式。谁知道怎么做?
非常感谢。
答案 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)