表单onsubmit不支持form .submit() [英] Form onsubmit doesn't work with form .submit()

查看:110
本文介绍了表单onsubmit不支持form .submit()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,我已经应用了一个函数onsubmit:

  var theForm = document.getElementById(myform) ; 
theForm.onsubmit = function FormSubmit(){
alert(something);
};

我在表单中添加了一个提交按钮< input type =提交value =submit/>



something 。很好!



我有一张图片,我想提交它:

 < img onclick =document.getElementById('myform')。submit(); SRC = mylocation/> 

但它不会生成函数...它不会提示东西在屏幕上。



编辑:我不想用jQuery。 Pure JS

解决方案

问题是事件处理程序在脚本调用事件时没有响应。 b

像下面这样说:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆