【发布时间】: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 仅出现一瞬间。
由于我刚刚学习,请原谅我的代码。
【问题讨论】:
-
如果表单中的某些内容出现一瞬间,那么最好是表单提交,然后页面重新加载。
-
为了更清楚,需要把按钮改成
<button onclick="myFunction2()" type="button">Click Here</button>
标签: javascript jquery html textfield