最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Event fault in Firefox - Stack Overflow

programmeradmin3浏览0评论

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'.

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'.

Share Improve this question edited Jan 6, 2023 at 10:10 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jan 11, 2011 at 9:37 homaxtohomaxto 5,7098 gold badges41 silver badges54 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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>
发布评论

评论列表(0)

  1. 暂无评论