JQuery html字符串输入框

标签 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>

然后,我想将消息显示到输入文本表单中。有谁知道怎么做吗?

非常感谢。

最佳答案

尝试

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

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

关于JQuery html字符串输入框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16755541/

相关文章:

jquery - 哪个是正确的 : spaces and/or tabs in jquery?

javascript - 使用 css2 的 Masonry 样式以获得更好的浏览器兼容性

html - 如何防止按钮向下溢出?

php - 比较数据库中的 200.000 条文本

c# - 从 C# 中的字符串中删除注释 block &lt;!-- -->

javascript - jQuery 从 HTML 字符串构建错误的 DOM

php - 使用 jQuery 在单击时 POST 到 MySQL

jquery - Bootstrap 模式登录和注册问题 :

java - 如何增加数组大小并将每个新元素添加到数组顶部?

javascript - 未捕获的类型错误 : Cannot set property 'value' of null occurs after second call