<input type="submit" class="sub" onClick="exefunction2()" id="button">
当我点击提交按钮时onClick
不管用。我怎样才能解决这个问题?我需要在提交表单时进行此操作,因为onClick
事件包含值。
最好的方法是在表单标签上调用方法,如下所示:
<form onsubmit="return exefunction2();">
...
</form>
返回false
不会提交表格,true
将提交!
要发布更多数据(使用 exefunction2 构建),您可以使用此
<script type="text/javascript">
function exefunction2(form) {
//add dynamic values
var dynValues = {
"val1": 1,
"val2": "bla"
};
for(var name in dynValues) {
//check if field exists
var input = null;
if(document.getElementsByName(name).length === 0) {
input = document.createElement('input');
input.setAttribute('name', name);
input.setAttribute('type', 'hidden');
form.appendChild(input);
}
else {
input = document.getElementsByName(name)[0];
}
input.setAttribute('value', dynValues[name]);
}
return true;
}
</script>
<form onsubmit="return exefunction2(this);">
<input type="submit" />
</form>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)