jsfiddle中的onsubmit无法正常工作 [英] onsubmit in jsfiddle not working

查看:86
本文介绍了jsfiddle中的onsubmit无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用onsubmit来调用javascript中的函数,但是它不起作用.我曾尝试寻找类似的问题,但没有任何效果.我也尝试过使用提交"按钮onclick,但这似乎也不起作用.

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'>

我希望它可以使用纯JS,而不是jquery.

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

这是小提琴.

推荐答案

默认情况下,提琴手将脚本添加到onload处理程序中,如下所示,因此脚本中创建的所有函数/变量都将在onload处理程序的范围内.当您使用内联事件处理程序时,脚本将在无法找到该方法的全局范围内寻找该方法

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
}

所以在左侧面板的Frameworks&第二个选择框中的扩展名选择No Wrap - In bodyNo Wrap - In Head

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

这篇关于jsfiddle中的onsubmit无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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