Why isn't my JavaScript working in JSFiddle?

前端 未结 7 1345
萌比男神i
萌比男神i 2020-11-21 05:11

I can\'t find out what is the problem with this JSFiddle.

HTML:


Jav

7条回答
  •  情书的邮戳
    2020-11-21 05:24

    The function is being defined inside a load handler and thus is in a different scope. As @ellisbben notes in the comments, you can fix this by explicitly defining it on the window object. Better, yet, change it to apply the handler to the object unobtrusively: http://jsfiddle.net/pUeue/

    $('input[type=button]').click( function() {
       alert("test");   
    });
    

    Note applying the handler this way, instead of inline, keeps your HTML clean. I'm using jQuery, but you could do it with or without a framework or using a different framework, if you like.

提交回复
热议问题