今天调试js时遇见一问题,form的onsubmit属性中的方法在提交时没反应?于是直接Google了解onsubmit方法的触发事件,总结如下:
onsubmit属性的触发必须是在form中用input并且type=submit这样的button提交时才会触发,否则不会触发。
而在官方文档上也找到了如下说明:
The submit method does not invoke the onsubmit event handler. Call the onsubmit event handler directly. When using Microsoft® Internet Explorer 5.5 and later, you can call the fireEvent method with a value of onsubmit in the sEvent parameter.
而我的代码中没有触发onsubmit方法正是由于我是用自定义的按钮提交form.submit()方法,所以如果要触发,必须手动将onsubmit要执行的函数放置在form.submit()之前
onsubmit属性的触发必须是在form中用input并且type=submit这样的button提交时才会触发,否则不会触发。
而在官方文档上也找到了如下说明:
The submit method does not invoke the onsubmit event handler. Call the onsubmit event handler directly. When using Microsoft® Internet Explorer 5.5 and later, you can call the fireEvent method with a value of onsubmit in the sEvent parameter.
而我的代码中没有触发onsubmit方法正是由于我是用自定义的按钮提交form.submit()方法,所以如果要触发,必须手动将onsubmit要执行的函数放置在form.submit()之前