我不知道'function(event)'这句话的意思
Event.add(apple,'click',function(event) {
Event.stopPropagation(event);
});
参数'event'不是javascript的唯一关键字吗?
关键字可以作为某个函数的参数吗?
我理解以下代码的含义:
function(test) {
alert(test);
}
但是我不明白这个:
function(event)...
有人可以给我解释一下吗?
最佳答案
The event object is always passed to the handler and contains a lot of useful information what has happened.
Different types of events provide different properties. For example, the onclick event object contains:
event.target
- the reference to clicked element. IE uses event.srcElement instead.event.clientX
/event.clientY
- coordinates of the pointer at the moment of click.Information about which button was clicked and other properties. Please visit this link.
It answers all your questions very simply
来源http://javascript.info/tutorial/obtaining-event-object
示例:
就像在 HTML 中你分配了这样的事件
<button onclick="alert(event)">See the event</button>
然后
function alert(event) {
// event.type contains whether this event was invoked in the result of a click etc
// event.target would contain the reference to the element which invoked this method/event
}
关于javascript - js中 'function(event)'是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25594427/