表单onsubmit不支持form .submit() [英] Form onsubmit doesn't work with form .submit()
问题描述
我有一个表单,我已经应用了一个函数onsubmit:
var theForm = document.getElementById(myform) ;
theForm.onsubmit = function FormSubmit(){
alert(something);
};
我在表单中添加了一个提交按钮< input type =提交value =submit/>
我有一张图片,我想提交它:
< img onclick =document.getElementById('myform')。submit(); SRC = mylocation/>
但它不会生成函数...它不会提示东西
在屏幕上。
编辑:我不想用jQuery。 Pure JS
像下面这样说:
var theForm = document.getElementById(myform);
函数FormSubmit(){
alert(something);
};
theForm.onsubmit = FormSubmit;
然后手动调用图片的功能 onclick
(); document.getElementById('myform')。submit();这是一个很好的例子。 SRC = mylocation/>
I have a form and I have applied a function onsubmit:
var theForm = document.getElementById("myform");
theForm.onsubmit = function FormSubmit() {
alert("something");
};
I have added in my form a submit button <input type="submit" value="submit"/>
The something
text is alerted. Great!
I have an image and I want to make it to submit the form:
<img onclick="document.getElementById('myform').submit();" src="mylocation"/>
But it doesn't make the function... it doesn't alert something
on screen.
EDIT: I don't want something with jQuery. Pure JS
The problem is event handlers doesn't respond when the event called by script.
Say like bellow
var theForm = document.getElementById("myform");
function FormSubmit() {
alert("something");
};
theForm.onsubmit = FormSubmit;
And call manually the function onclick
of image like bellow
<img onclick="FormSubmit();document.getElementById('myform').submit();" src="mylocation"/>
这篇关于表单onsubmit不支持form .submit()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!