Skip to content

Instantly share code, notes, and snippets.

@h4
Created April 2, 2012 19:43
Show Gist options
  • Save h4/2286667 to your computer and use it in GitHub Desktop.
Save h4/2286667 to your computer and use it in GitHub Desktop.
События в JavaScript
<script type=”text/javascript”>
function yourMessage(){
alert("Функция");
}
</script>
</head>
<body onload="yourMessage()">
</body>
<html>
<head>
<script type="text/javascript">
function show_coords(event)
{
x=event.clientX;
y=event.clientY;
alert("X coords: " + x + ", Y coords: " + y);
}
</script>
</head>
<body onmousedown="show_coords(event)">
<p>Щелкните кнопкой мыши.</p>
</body>
</html>
<html>
<head>
<script type="text/javascript">
function whichButton(event) {
if (event.button == 2) {
alert("Вы щелкнули правой кнопкой мыши!");
} else {
alert("Вы щелкнули левой кнопкой мыши!");
}
}
</script>
</head>
<body onmousedown="whichButton(event)">
<p>Щелкните кнопкой мыши.</p>
</body>
</html>
<html>
<head>
<script type="text/javascript">
function whichButton(event) {
alert(event.keyCode);
}
</script>
</head>
<body onkeyup="whichButton(event)">
<p>Нажмите клавишу на клавиатуре.</p>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function scope_mem() {
var a = 20;
document.onclick = function(){alert(a); };
}
scope_mem();
</script>
</head>
<body>
<p>Текст документа.</p>
</body>
</html>
html>
<head>
<title>event bubbling</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function fun_div(){
alert("event in div");
}
function fun_span(){
alert("event in span");
}
</script>
</head>
<body>
<div onclick = "fun_div();">
<span onclick = "fun_span();">Место для щелчка</span></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment