JavaScript Event Methods

Source: Internet
Author: User

<! 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.