by next scenario: user does something and this action is
an event for browser. JavaScript observes pages in the browser. And if event has occurred, script will be activated.[1]
[1]
[1]
[2]
First way: inline adding of JavaScript into HTML. If we use this technique, we should update HTML-page and set some JS code in onevent attribute of HTML-element.
Never use this way, because it influences HTML and JavaScript simultaneously. So let's look at the next option!
[1]
[2]
For example, your button has id btn:
Where action is some function
defined as function action () { . . . }
Then desired object will be created automatically. Next you can use an onclick property:
[1]
[2]
btn.addEventListener(“click”, action, false);
But this method doesn't work in IE. For IE you should use:
Next method helps solve this and some other problems:
btn.attachEvent(“onclick”, action);
[1]
[2]
[1]
[1]
W3C browsers supports both phases whereas in IE only bubbling is supported.
For example: [1]
There are three nested elements like
btn.addEventListener(“click”, action, false);
Where action was defined as:
function action (e) { . . . }
[1]
You have a possibility to use a cross-browser solution.:
function action (e) {
e = e || window.event;
. . .
}
[1]
[2]
If you don't need a default behavior, you can cancel it. Use object event and next methods for this purpose:
e.preventDefault();
e.stopPropagation();
for discarding bubbling and capturing.
for aborting default browser behavior.
.
[1]
[2]
[1]
[2]
[3]
[41
var a = 10;
test();
function test () {
a = 30;
var b = 40;
}
var b = 20;
console.log(a, b);
{x: 10, y: 20}
{x: 15, y: 50}
[1]
[2]
[3]
var pi = getPi();
. . .
L = 2*pi()*R;
[1]
[3]
[2]
Если не удалось найти и скачать доклад-презентацию, Вы можете заказать его на нашем сайте. Мы постараемся найти нужный Вам материал и отправим по электронной почте. Не стесняйтесь обращаться к нам, если у вас возникли вопросы или пожелания:
Email: Нажмите что бы посмотреть