【发布时间】:2019-02-13 08:20:21
【问题描述】:
我试图在提交之前在表单中设置hidden 类型的input,但我不明白为什么它没有设置我的字段:
HTML
<form id="createForm" method="post" action="[myhost]/[myaddress]/[mypath]" enctype="multipart/form-data" >
<input type="hidden" id="ticket" name="Ticket" />
</form>
<input id="setterInput" type="text"/>
<button onclick="methods.setHidden()"></button>
JS
window.methods = {
setHidden: function () {
var form = document.getElementById('createForm');
var setter=document.getElementById('setter');
var input = document.getElementsByName('Ticket');
input.value = setter.value;
console.log(input.value); //has the desired value
//looking with the debugger in my form at the target input, the value is still default
}
}
当我在console.log 行中设置调试器时,设置了input 变量。但它不会反映在form 中。
当我滚动表单时,input 的值仍然是“”。
有什么建议吗?
【问题讨论】:
标签: javascript forms hidden ecmascript-5