【问题标题】:HTML textbox default value update with every input每次输入都会更新 HTML 文本框默认值
【发布时间】:2014-06-06 19:17:31
【问题描述】:

我这里有这个简单的 Html 代码。

<form action="" method="post">
    Text Box:<input type="text" name="host" value="default value" size=30 onchange="updateTextBox()" />
    <input type="submit" name="submit" value="update value in text box to current value"/>
</form>

每次单击按钮时,我都希望将文本框的默认值更新为我最近输入的值。

【问题讨论】:

  • 到目前为止你做了什么?

标签: html textarea


【解决方案1】:
<script>
    /* give a name to the form and write it where "form_name" is */
    var newText = document.forms["form_name"]["host"].value;

    /* add this chunk in the submit button (onclick = "changeText()") */
    function changeText()
    {
        /* give an id to the text box input tag and replace "input_id" with that */
        document.getElementById("input_id").value = newText; 
    }
</script>

【讨论】:

  • 你能给我举个例子吗?它似乎不起作用...
  • changeText(e) { event.preventDefault(); //这里的功能 $('form').submit(); }
猜你喜欢
  • 1970-01-01
  • 2019-10-18
  • 2023-03-15
  • 2015-09-20
  • 2013-09-02
  • 2020-09-18
  • 1970-01-01
  • 1970-01-01
  • 2013-10-14
相关资源
最近更新 更多