Firefox中的事件问题 [英] event problem in Firefox

查看:68
本文介绍了Firefox中的事件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Firefox中访问'event'时遇到问题。以下代码在Chrome中运行良好,但在Firefox中我收到事件未定义错误。

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>

据我所知,Firefox没有找到任何名为event的变量,但我找不到任何东西除了'event'之外,还应该在Firefox中定义。

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.

那么我怎么能在Firefox中访问当前事件,或者重新设计应该如何?
请注意,我有不同的行为'type'提供不同的值。

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

推荐答案

试试这个:

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

你不允许使用event参数的地方通过。嗯,你是,但它被传递到类型变量。现在事件将包含 currentTarget 值。

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.

编辑

哦等等!您也希望传递行类型。

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

这应该这样做!

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

这篇关于Firefox中的事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆