为什么总是获取不到这两个input的值?

网点参数: <textarea id="dotinput" style="width:200px;height:200px;"></textarea>
<br/>
油墨扩大率: <input type="text" id="spreadrateinput" />
扩散精度: <input type="text" id="spreaddegreeinput" />
<input type="button" value="提交" onclick="fun()" />
        
        
var inkmax = document.getElementById('spreadrateinput');
var times = document.getElementById('spreaddegreeinput');
console.log(inkmax.value);
console.log(times.value);
阅读 1.7k
2 个回答

:javascript是触发机制的,不是你输入数据就会执行consloe语句;
:可以用onblur当input失去焦点的时候触发事件;
:如果是提交到后台,要用form表单的形式提交,尽量不要用getvalue的方式,安全性差;

<input type="text" id="spreadrateinput" onChange="changeFunction()" />
<input type="text" id="spreaddegreeinput" onChange="changeFunction()" />
changeFunction() {
var inkmax = document.getElementById('spreadrateinput');
var times = document.getElementById('spreaddegreeinput');
console.log(inkmax.value);
console.log(times.value);
}

這樣如何?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题