K
knocte
Hello group.
In the following testcase I attach to the final of the message, I have
two questions:
1) According to comment # 1, how can I pass an argument to the
function that way?
2) According to comment # 2, why this special structure for the "for"
statement is not working?
Testcase:
<html><head><title>Testcase</title>
<script type="text/javascript" language="JavaScript">
<!--
function Alert(number) {
window.alert("A element clicked!(number:" + number + ")");
return false;
}
function ApplyAlerts() {
var oAElement = window.document.getElementById('alert1');
oAElement.onclick = Alert; //how can I pass an argument? [comment
#1]
var aElements = window.document.getElementsByTagName('a');
for (var i = aElts.length; i--; ) { var oElement = aElts; //this
works
//for (oElement in aElts){ //Why this doesnt work? [comment #2]
if (oElement.id)
if (oElement.id == 'alert2')
oElement.onclick = Alert;
}
}
window.onload = ApplyAlerts;
//-->
</script></head>
<body id="body">
<div id="test">
<a id="alert1" name="alert1" href="http://www.google.com"
target="_blank">Link1</a><br />
<a id="alert2" name="alert2" href="http://www.google.com"
target="_blank">Link2</a>
</div>
</body></html>
In the following testcase I attach to the final of the message, I have
two questions:
1) According to comment # 1, how can I pass an argument to the
function that way?
2) According to comment # 2, why this special structure for the "for"
statement is not working?
Testcase:
<html><head><title>Testcase</title>
<script type="text/javascript" language="JavaScript">
<!--
function Alert(number) {
window.alert("A element clicked!(number:" + number + ")");
return false;
}
function ApplyAlerts() {
var oAElement = window.document.getElementById('alert1');
oAElement.onclick = Alert; //how can I pass an argument? [comment
#1]
var aElements = window.document.getElementsByTagName('a');
for (var i = aElts.length; i--; ) { var oElement = aElts; //this
works
//for (oElement in aElts){ //Why this doesnt work? [comment #2]
if (oElement.id)
if (oElement.id == 'alert2')
oElement.onclick = Alert;
}
}
window.onload = ApplyAlerts;
//-->
</script></head>
<body id="body">
<div id="test">
<a id="alert1" name="alert1" href="http://www.google.com"
target="_blank">Link1</a><br />
<a id="alert2" name="alert2" href="http://www.google.com"
target="_blank">Link2</a>
</div>
</body></html>