在Chrome不工作的DIV容器内文本的JavaScript的onclick()事件 [英] javascript onclick() event not working in chrome for text within div container

查看:416
本文介绍了在Chrome不工作的DIV容器内文本的JavaScript的onclick()事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是不是在工作铬,但在IE和Firefox的作​​品:

The following is not working in chrome, but works in IE and Firefox:

<div id="removeField" onclick="remove(0);" style="cursor: pointer;">-Remove</div>

在remove()函数不会被调用。任何想法,为什么?

The remove() function does not get called. Any idea why?

推荐答案

删除是在Chrome DOM元素的成员函数。在您的控制台,您可以通过运行看到这一点:

remove is a member function of DOM elements in Chrome. In your console, you can see this by running:

> document.createElement("div").remove
function remove() { [native code] }

在一个内联的事件处理程序,该元素的所有属性(包括成员函数)可作为顶层的变量。内嵌code是一个有效的内部 <$ C运行$ C>与(thisElement) 块。在联事件code的情况下,标识符删除删除元素的方法,没有全球范围的删除功能。

In an inline event handler, all the properties (including member functions) of that element are available as top-level variables. Inline code is effectively run inside a with(thisElement) block. In the context of the inline event code, the identifier remove refers to the remove method of the element, not the global-scope remove function.

改变功能名称的东西,不与元素的方法名称发生冲突,或使用 window.remove 明确。

Change the function name to something that doesn't collide with the method names of the element, or use window.remove explicitly.

这previous答案的处理与<$ C类似的情况下修改$ C>在IE启动方法。的)

(Modified from this previous answer of mine handling a similar case with the start method in IE.)

这篇关于在Chrome不工作的DIV容器内文本的JavaScript的onclick()事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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