什么是JavaScript中的“click()” [英] What is 'click()' in JavaScript

查看:173
本文介绍了什么是JavaScript中的“click()”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在FireFox中使用JavaScript,遇到了以下示例中说明的问题:

I was playing around with JavaScript in FireFox, and hit a problem that is illustrated in the following example:

<HEAD>
<script type="text/javascript">
function click()
{
    alert("click");
}

</script>
</HEAD>

<BODY>

<input type="radio" onclick="click()">
</BODY>

当我点击单选按钮时,没有任何反应,也没有错误(在Firebug中)

When I click on the radio button, nothing happens, and no errors (in Firebug)

如果我将函数的名称更改为do_click,并更改onclick,则会收到警报。

If I change the name of the function to do_click, and change the onclick, then I get the alert.

所以问题是:发生了什么? click似乎不是保留字或现有符号

So question is: what is happening? click does not appear to be a reserved word, or an existing symbol

推荐答案

内联事件处理程序中的代码范围限定为元素,好像它是在中带块。

Code within inline event handlers is scoped to the element, as if it was in a with block.

因此,在 onclick handler,名称点击解析为元素的点击方法。

Therefore, within the onclick handler, the name click resolves to the element's click method.

这可以通过编写 alert(nodeName)<演示处理程序中的/ code>

This can be demonstrated by writing alert(nodeName) in the handler

这篇关于什么是JavaScript中的“click()”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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