【问题标题】:Value of text field/ text box does NOT change permanently文本字段/文本框的值不会永久更改
【发布时间】:2016-08-13 23:52:12
【问题描述】:

这是我的 HTML,

按钮和文本字段被声明

按钮调用函数:

<div>
<form>
    <button onclick="myFunction2()">Click Here</button>
    <input type="text" name="textbox" id="text" style="width: 10px"/>
</form>

这里我简单声明一些变量(JAVASCRIPT):

var integers = {
        'one': 1,
        'two': 2,
        'three': 3,
        'fiveHundred': 500,
    }

我尝试在此处更改文本字段值:

function myFunction2() {
        document.getElementById("text").value = integers["one"];
    }

目标是让文本字段显示 1,但数字 1 仅出现一瞬间。

由于我刚刚学习,请原谅我的代码。

【问题讨论】:

  • 如果表单中的某些内容出现一瞬间,那么最好是表单提交,然后页面重新加载。
  • 为了更清楚,需要把按钮改成&lt;button onclick="myFunction2()" type="button"&gt;Click Here&lt;/button&gt;

标签: javascript jquery html textfield


【解决方案1】:
  <form>
    <button onclick="myFunction2()" type="button">Click Here</button>
    <input type="text" name="textbox" id="text" style="width: 100px"/>
  </form>

【讨论】:

    猜你喜欢
    • 2023-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多