Ciao.
Voglio passare ad una gestione + avanzata
degli eventi ma sono incastrato su un semplice script (2 righe)
Prima facevo una cosa del genere:
Adesso almeno su Firefox dovrei fare una cosa delCodice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" language="javascript">
openLink=function()
{
var div=document.getElementById('testdiv');
div.onclick=function(){
alert('Reacting to Event bubble phase');
}
}
window.onload=openLink;
</script>
</head>
<body>
<div id="testdiv">
[url="#"]Click here activate the alert method[/url]</p>
</div>
</body>
</html>
genere :
Ma non funzionaCodice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="javascript">
alertBox=function()
{
alert('Reacting to Event bubble phase');
}
var div=document.getElementById('testdiv');
div.addEventListener('click',alertBox,false);
</script>
</head>
<body>
<div id="testdiv">
[url="#"]Click here activate the alert method[/url]
</div>
</body>
</html>
(( mi sapete spiegare dove sbaglio ?
Ho provato anche a fare una cosa del genere ma l'evento
scatta nell'intero body:
CiaoCodice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html> <head> <title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="javascript">
alertBox = function ()
{
alert('caught click');
}
function myClickListener(event)
{
if (document.addEventListener)
{
document.addEventListener('click', event, false);
}
else
{
document.attachEvent('onclick', event);
}
}
window.onload = myClickListener(alertBox);
</script>
</head>
<body>
<div id="testdiv">
[url="#"]Click here activate the alert method[/url]
</div>
</body>
</html>
![]()