The script and processing of events in JavaScript
In javascript (or jscript, versions javascript firms microsoft) are two features: the first - that in him the functions are supported only, the second - that this language is clear for all browsers. The most habitual way of transfer of event to an element is an announcement of the name of function in tege an element. We shall notice, that we need to write down not simply "myclickcode", and " myclickcode () " for conformity of a syntactic design javascript. In html the document it will look so:
<h2 onclick = " myclickcode () ">
The text reacting to event
</h2>
...
<script language=javascript>
function myclickcode () {
alert (' you have clicked the Text! ');
}
</script>
It is good for job with separate elements and how to act{arrive} if necessary processings of events by the whole document? In this case indexes on obrabotchiki events can be placed in teg <body>:
<body onmousemove = " mymousemovecode () " onclick = " myclickcode ()>
Besides it is possible to connect a code of processing inside tega an element. Thus such design of language jscript is used:
<h2 language=jscript onclick = " alert (' you have clicked the Text! '); ">
The text reacting to event
</h2>
As jscript is the language of a browser determined by default, it is possible to lower{omit} attribute "language=jscript", having made a design of more compact:
<h2 onclick = " alert (' you have clicked the Text! '); ">
The text reacting to event
</h2>
And, at last, it is possible to create separate section <script> for each event which to us needs to be processed:
<h2 id=myheading> the Text reacting to event </h2>
...
<script language=javascript for=myheading event=onclick>
alert (' you have clicked the Text! ');
</script>

© Web Development Company Conkurent, LLC 2008-2009. All rights reserved. |