<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<style type= "Text/css" >
div{
Background-color:lightblue;
margin:5px;
padding:5px;
}
</style>
<script src= "Scripts/eventutil.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
var changesize = function () {
var otxt = document.getElementById (' txt ');
Otxt.size + = 5;
}
var showmessage = function () {
Alert (' click event ');
Alert (' Event type: ' + event.type);
}
Window.onload = function () {
document.getElementById (' btn1 '). onclick =
function () {
Alert (' Btn1 click event ');
}
}
</script>
<body>
<input type= "text" id= "TXT" size= "ten"/>
<input type= "button" value= "Extended" onclick= "changesize ()"/>
<input type= "button" value= "Point Me" onclick= "showmessage ()"/>
<input type= "button" id= "BTN1" value= "button"/>
<p> only three draw chance! </p>
<input id= "btnlottery" type= "button" value= "lottery"/>
<div id= "Divresult" >
</div>
<script type= "Text/javascript" >
var times = 0; Number
var arr = [' 10 million ', ' Goddess One ', ' Bugatti Veyron ', ' Seaview Villa ', ' All-hero full skin ', ' unlimited recharge ', ' every bet will win '];
var btnlottery = document.getElementById (' btnlottery ');
Btnlottery.onclick = function () {
if (Times >= 3)
{
Alert ("You've already smoked three times!" ");
This.onclick = null;
Return
}
times++;
var n = math.floor (Math.random () * arr.length); The array is randomly pumping a
var divresult = document.getElementById (' Divresult ');
divresult.innerhtml = "<p> You are the first" + Times + "draws, the draw is:" + arr[n] + "</p>"
}
</script>
<input type= "button" id= "Btndom2test" value= "Test DOM2 event handling"/>
<input type= "button" id= "Btndeldom2test" value= "test DOM2 Delete event handling"/>
<script type= "Text/javascript" >
var sayhi = function () {
Alert (' hello! ');
}
var btndom2test = document.getElementById (' btndom2test ');
Btndom2test.addeventlistener (' click ', function () {
Alert (' You clicked: ' + This.value ');
}, False);
Btndom2test.addeventlistener (' Click ', Sayhi, false);
var btndeldom2test = document.getElementById (' btndeldom2test ');
var del = function () {
Btndom2test.removeeventlistener (' click ', function () {
Alert (' You clicked: ' + This.value ');
}, False);
Btndom2test.removeeventlistener (' Click ', Sayhi, false);
}
Btndeldom2test.addeventlistener (' Click ', Del, false);
ie9+
Btndom2test.attachevent ("onclick", sayhi);
Btndom2test.attachevent ("onclick", function () {
Alert ("IE event binding!");
//});
</script>
<label for= "Txtphonenum" > Please enter your mobile phone number </label>
<input type= "text" id= "Txtphonenum"/>
<script type= "Text/javascript" >
var txtphonenum = document.getElementById (' Txtphonenum ');
Eventutil.addhandler (Txtphonenum, ' keypress ', function () {
var e = eventutil.getevent ();
alert (E.keycode);
are not numbers.
if (E.keycode < | | E.keycode > 57) {
Eventutil.preventdefault (e);
}
});
</script>
<form id= "Frmdemo" action= "submitpage.htm" >
<label for= "Txtuid" > Account:</label>
<input type= "text" id= "Txtuid"/><br/>
<label for= "txtpwd" > Password:</label>
<input type= "Password" id= "txtpwd"/><br/>
<input type= "button" id= "btnsubmit" value= "Login"/>
</form>
<script type= "Text/javascript" >
var txtuid = document.getElementById (' Txtuid ');
var txtpwd = document.getElementById (' txtpwd ');
var btnsubmit = document.getElementById (' btnsubmit ');
var Frmdemo = document.getElementById (' Frmdemo ');
Eventutil.addhandler (btnsubmit, ' click ', function () {
Alert (' I submitted it! ‘);
if (Txtuid.value = = "Admin") {
Frmdemo.submit (); Submit
}
else {
Return
}
});
Eventutil.addhandler (Txtuid, ' KeyDown ', function () {
var e = eventutil.getevent (); Enter.keycode = 13;
if (E.keycode = = 13) {
Txtpwd.focus ();
Eventutil.preventdefault (e);
}
});
</script>
<div onclick= "this.style.backgroundcolor= ' red '; Event.cancelbubble=true; " >div1
<div onclick= "this.style.backgroundcolor= ' Blue ';" >div2
<div onclick= "this.style.backgroundcolor= ' black ';" >div3
</div>
</div>
</div>
</body>
JavaScript Event Methods