【问题标题】:JQuery html string input boxJQuery html字符串输入框
【发布时间】:2013-05-21 06:27:47
【问题描述】:

我有这个功能:

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>

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

非常感谢。

【问题讨论】:

标签: jquery html string forms input


【解决方案1】:

试试

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

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

【讨论】:

  • 非常感谢您的帮助!
【解决方案2】:

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

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

【讨论】:

  • 非常感谢您的帮助!
【解决方案3】:

jQuery

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

HTML

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

好的,对于回答您的问题的相关链接,也许这有点矫枉过正,但它们都回答了您的问题。

【讨论】:

  • 非常感谢您的帮助!
猜你喜欢
  • 2012-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-20
  • 2017-03-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多