Home > Web Front-end > JS Tutorial > body text

javascript A function responds to multiple events on the same element_javascript skills

WBOY
Release: 2016-05-16 18:49:14
Original
1042 people have browsed it
复制代码 代码如下:

var testButton=document.getElementById("testButton");
function handlerTest()
{
var oEvent=window.event;//for IE
//var oEvent=arguments[0];// for DOM
if(oEvent.type=="click")
{
alert("click");
}
else if(oEvent.type=="mouseover")
{
alert("mouseover");
}
else
{
alert(oEvent.keycode);
}
}
testButton.onclick=handlerTest;
testButton.onmouseover=handlerTest;

html元素如下:
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!