Why this JSFiddle does not work [duplicate]

2019-01-15 10:56发布

问题:

This question already has an answer here:

  • jsFiddle: no connection between html and js? Can't call simple function from button? 1 answer

I have written a simple function:

function clickedMe() {
  alert(this + " : " + this.tagName + " : " + this.id);
}

And I am calling it on click event of button element

<button onclick="clickedMe()">button</button>

This works when I created a standalone HTML page locally. However it does not seem to work on JSFiddle. Here is the link: http://jsfiddle.net/Mahesha999/fACce/

Whats wrong here?

回答1:

Select no wrap - in <head>/<body> .

It doesn't work because clickedMe is not in the global scope.