onsubmit in jsfiddle not working

人盡茶涼 提交于 2019-12-12 02:56:48

问题


I am trying to use onsubmit to call a function in javascript but it is not working. I have tried looking similar questions but nothing worked. I have also tried onclick with the submit button, that too doesn't seem to work.

<form method="POST" onsubmit="return add();" name='contact'>

I want this to work with pure JS, not jquery.

Here is the fiddle.


回答1:


By default fiddler adds the script in a onload handler as given below, so all the functions/variables created in the script will be inside the scope of the onload handler. When you use the inline event handler the script will look for the method in the global scope where the method won't be found

window.onload = function(){
    //our script here
}

so in the left panel under Frameworks & Extensions in second select box select No Wrap - In body or No Wrap - In Head



来源:https://stackoverflow.com/questions/30750369/onsubmit-in-jsfiddle-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!