简体   繁体   English

jsFiddle-我缺少什么?

[英]jsFiddle - what am I missing?

Quick question for people familiar with jsFiddle: why doesn't this run the function when the button is clicked? 熟悉jsFiddle的人的一个快速问题:为什么单击按钮时此命令不运行该功能?

I'm sure I'm missing something obvious, but can't get it working. 我确定我缺少明显的东西,但是无法正常工作。

You need to select the "no wrap (head)" option in the sidebar. 您需要在侧栏中选择“不包裹(头部)”选项。 Otherwise, your f() function gets wrapped up in some $(function() { /*...*/ }); 否则,您的f()函数将包裹在某些$(function() { /*...*/ }); stuff and is not visible to be set in an onclick attribute: 东西,在onclick属性中不可见:

http://jsfiddle.net/ambiguous/a6rQX/ http://jsfiddle.net/ambiguous/a6rQX/

Under Framework select "no wrap (head) 在框架下,选择“不换行(头)

Click the Run button. 单击运行按钮。

It should now work. 现在应该可以了。

It is because the function with name f() local to the onReady function, so it is not available in the global context. 这是因为名称为f()的函数位于onReady函数的本地,因此在全局上下文中不可用。

onReady(){
    function f(){
        xyz
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM