'event' equivalent in firefox

后端 未结 4 1517
攒了一身酷
攒了一身酷 2020-12-03 22:32

I am using the following code and it works perfectly fine in Chrome.

function dayBind(xyzValue) {
    if(event.type == \'click\')
       alert(\'Mouse Clicke         


        
4条回答
  •  甜味超标
    2020-12-03 23:01

    I am working in a plugin's callback function. I cannot call it myself.

    One simple question to your suggestion: when you write: onclick="whatever(event)" you are writing javascript in the value of onclick attribute, right?

    Why can't you make the same function call inside some other function like this:

    function foo(){ whatever(event); // this is also javascript }

    // But this doesn't work for me in FireFox 10.0.2

    The code in the "onclick" attribute should be thought of as part of a function that the browser creates for you. That function automatically has the "event" parameter available. Writing the attribute as I did in the answer cause that parameter to be passed on the your other function.

    Really, you should read about the jQuery API and use that to bind event handlers instead of using "onclick" and other similar attributes.

提交回复
热议问题