【问题标题】:onclick-event doesn't work in Firefox - works in Internet Exploreronclick-event 在 Firefox 中不起作用 - 在 Internet Explorer 中起作用
【发布时间】:2014-12-02 19:59:02
【问题描述】:

我已经实现了一个名为:remove(this) 的 onclick 事件。它在 Internet Explorer 中运行良好,但在 Firefox 中却不行。我在remove函数上设置了一个断点,所以我看到IE调用了这个函数而FF没有。 (使用 Firebug 和 IE DeveloperTools 调试)

Internet Explorer:

<INPUT onclick="remove( this )" id=NBGTEST-1075_0002__Update__DeleteButton 
title="Remove Spawn" class="update field-button" type=button value=Delete 
name=NBGTEST-1075_0002__Update__SpawnButton>

火狐:

<input id="NBGTEST-1075_0005__Update__DeleteButton" 
class="update field-button" type="button" onclick="remove( this )" 
value="Delete" title="Remove Spawn" name="NBGTEST-1075_0005__Update__SpawnButton">

输入按钮的参数相同,只是顺序不同,但这不应该是错误。

这个程序: 有一个按钮A。当点击按钮A时,会生成一个按钮B。按钮 B 可以移除。函数 remove() - 再次删除按钮。 当我按下删除按钮时,按钮被隐藏但该行仍然可见。该行将在 remove() 函数中删除

按钮 A(添加按钮)的代码:

IE:

<INPUT onclick="add( this )" id=NBGTEST-1075_Main__Update__SpawnButton 
title="Create Spawn" class="update field-button" type=button value="Add Spawn" 
name=NBGTEST-1075_Main__Update__SpawnButton>

FF:

<input id="NBGTEST-1075_Main__Update__SpawnButton" class="update field-button" 
type="button" onclick="add( this )" value="Spawn MR" title="Create Spawn" 
name="NBGTEST-1075_Main__Update__SpawnButton">

两个浏览器都会触发 add(this) 事件。

我用 IE11 和 FF 32.0.3 测试过

有趣的事实:当我在 Firefox 中创建 Internet Explorer 选项卡时,它也可以工作!

移除功能:

function remove( button )
{
    if( isButton( button ) && isUpdateSection( button.id ) )
    {
         //here I remove the button/row
    }
  return( false );
}

【问题讨论】:

  • 该代码也适用于早期的 Firefox 版本。
  • 你能展示add(this)remove(this)的js函数吗?
  • 这些函数的代码比较长。但问题是,该函数没有在 Firefox 中调用
  • 提交jsFiddle 让我们查看问题。
  • 很难,因为只有javascript代码就有5000多行代码。我尽量把问题抽象出来。

标签: javascript html internet-explorer firefox dom


【解决方案1】:

我修好了。我只是在 removes() 中从 remove() 更改了函数名称。据推测,remove() 是一个内部 javascript 函数,而 firefox 使用该函数。相反,Internet Explorer 检测到我定义了自己的 remove() 函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 2017-12-05
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    相关资源
    最近更新 更多