Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a problem accessing the 'event' in Firefox. The following code works fine in Chrome, but in Firefox I get a "event is not defined" error.

<tr onclick="rowSelected('thisRowType')">
  ... row content ...
</tr>

<script type="text/javascript">
    function rowSelected(type) {
        var eventRow = event.currentTarget; // here I get the error
    }
</script>

I understand that Firefox does not find any variable called event, but I have not been able to find anything other than 'event' should also be defined in Firefox.

So how could I access the current event in Firefox, or how should a redesign look like? Please note that I have different rows supplying different values for 'type'.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
414 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try this instead:

function rowSelected(event, type) {
    var eventRow = event.currentTarget; // here I get the error
}

You where not allowing the event argument to be passed. Well, you were but it was being passed into the type variable. Now event will contain the currentTarget value.

EDIT

Oh wait! You wish to pass the row type too.

This should do it!

<tr onclick="rowSelected(event, 'thisRowType')">
  ... row content ...
</tr>

<script type="text/javascript">
    function rowSelected(event, type) {
        var eventRow = event.currentTarget; // here I get the error
        alert(type);
    }
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...