OK, so I have a couple, which might turn out to be too ordinary questions for this forum regarding unobtrusive event handling.
As I understand it, a properly configured document will look something like this:
<html>
<head>
<title>Title</title>
<script src="jsfile.js" type="text/javascript></script>
</head>
<body>
//Body content, like some form elements in my case
</body>
</html>
Jsfile.js will look something like this:
function a() {
}
function b()...
window.addEventListener('load', a, false);
document.getElementById("id").addEventListener('click', b, false);
document.myForm.typeSel.addEventListener('change', c, false);
//or to use better browser-compatible code...
function addEvent(obj,evt,fn) {
if (obj.addEventListener)
obj.addEventListener(evt,fn,false);
else if (obj.attachEvent)
obj.attachEvent('on'+evt,fn);
}
addEvent(window, 'load', a);
addEvent(document.getElementById('id'), 'click', b);
addEvent(document.myForm.typeSel, 'change', c);
, javascript, . ... , . , getElementById () getElementById , . loadEvents(), onload, addEvent() , . , , .
, addEvent , , ...
<input type="checkbox" id="test" />
<script type="text/javascript>
document.getElementById("test").onclick = func;
</script>
... . , , !
, : , "element.addEventListener('click', func, false)", "addEvent (, 'click', func)" "element.onclick = func" - script , ? getElementById ?
, - ?