JsFiddle中的代码不起作用 [英] Code in the JsFiddle is not working
问题描述
我有一个查询,因为我想准备一个JSFiddle。但它不适用于小型点击程序。其中只有两行代码。
HTML
<身体GT;
< button onclick =javascript:launchdialog();>点击我< /按钮>
< / body>
JavaScript
函数launchdialog(){
alert('test');
}
我在两行代码中没有发现任何错误。
请看这个 JSFiddle - http://jsfiddle.net/g47qqzra/
您可以在head或body中设置 No wrap
选项。
当您使用 使函数 I have one query, for that I wanted to prepare a JSFiddle. But it's not working for a small click program. Which has just two lines of code. HTML JavaScript I didn't find anything wrong in just two lines of code.
Please have a look at this JSFiddle - http://jsfiddle.net/g47qqzra/ You can set the option to When you use ReferenceError: functionName is not defined Making the function 这篇关于JsFiddle中的代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! onload 或
onDomReady
,您的代码被封装在另一个函数中,该函数在 load
或准备好
事件。因此,您的功能不能从该功能以外访问。而且你会得到错误
lockquote
ReferenceError:functionName没有定义
无包装
使它成为全局,可以从任何地方访问。
<body>
<button onclick="javascript:launchdialog();">Click Me</button>
</body>
function launchdialog() {
alert('test');
}
No wrap
in head or body.onload
or onDomReady
, your code is wrapped inside another function that is invoked on load
or ready
event. So, your function is not accessible from outside of that function. And you'll get error
no wrap
makes it global, can be accessed from anywhere.