I am newbie in jsfiddle

I have put a very simple javascript code in jsfiddle http://jsfiddle.net/5bMSp/1/

<script>
function alertme(){
    alert("HI");
}
</script>
<a href="#" onclick="alertme()">click</a>

This simple code works awesome in any browser but not in jsfiddle. Am I missing anything in the jsfiddle?

有帮助吗?

解决方案

By default, jsFiddle puts all of your code within an onload handler, like this:

window.onload = function() {
    // ...your code here...
};

That means your alertme function isn't a global, and it has to be for onclick attributes to work.

There's a drop-down on the left, near the top, that controls this behavior. Change it from onLoad to one of the "no wrap" options to make your function global.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top