<br> div{<br> background-color:lightblue;<br> margin:5px;<br> padding:5px;<br><br> }<br> <br> var changeSize = function () {<br> var oTxt = document.getElementById('txt');<br> oTxt.size += 5;<br> }</p> <p>var showMessage = function () {<br> alert('单击事件');<br> alert('事件类型:' + event.type);<br> }</p> <p>window.onload = function () {<br> document.getElementById('btn1').onclick = <br> function () {<br> alert('btn1单击事件');<br> }<br> }<br> 只有三次抽奖机会! <br> var times = 0; //次数<br> var arr = ['一千万', '女神一枚', '布加迪威龙', '海景别墅', '全英雄全皮肤','无限充值','逢赌必赢'];</p> <p>var btnLottery = document.getElementById('btnLottery');<br> btnLottery.onclick = function () {<br> if(times >= 3)<br> {<br> alert("你已经抽完三次了!");<br> this.onclick = null;<br> return;<br> }<br> times++;<br> var n = Math.floor(Math.random() * arr.length); //数组中随机抽一个<br> var divResult = document.getElementById('divResult');<br> divResult.innerHTML = "<p>您是第"+ times +"次抽奖,抽中的是:"+ arr[n] +"</p>"<br> }<br> <br> var sayHi = function () {<br> alert('Hello!');<br> }</p> <p>var btnDOM2Test = document.getElementById('btnDOM2Test');<br> btnDOM2Test.addEventListener('click', function () {<br> alert('您单击的是:' + this.value);<br> }, false);</p> <p>btnDOM2Test.addEventListener('click', sayHi, false);</p> <p>var btnDelDOM2Test = document.getElementById('btnDelDOM2Test');</p> <p>var del = function () {<br> btnDOM2Test.removeEventListener('click', function () { <br> alert('您单击的是:' + this.value);<br> }, false);<br> btnDOM2Test.removeEventListener('click', sayHi, false);<br> }<br> btnDelDOM2Test.addEventListener('click', del, false);</p> <p>//IE9+<br> //btnDOM2Test.attachEvent("onclick", sayHi);<br> //btnDOM2Test.attachEvent("onclick", function () {<br> // alert("IE事件绑定!");<br> //});<br> 请输入手机号码 <br> var txtPhoneNum = document.getElementById('txtPhoneNum');<br> EventUtil.addHandler(txtPhoneNum, 'keypress', function () {<br> var e = EventUtil.getEvent();<br> //alert(e.keyCode);<br> //都不是数字<br> if (e.keyCode < 48 || e.keyCode > 57) {<br> EventUtil.preventDefault(e);<br> }<br> });<br> 用户登录 账号: 密码: <br> var txtUID = document.getElementById('txtUID');<br> var txtPWD = document.getElementById('txtPWD');<br> var btnSubmit = document.getElementById('btnSubmit');<br> var frmDemo = document.getElementById('frmDemo');</p> <p>EventUtil.addHandler(btnSubmit, 'click', function () {<br> alert('我提交了!');<br> if (txtUID.value == "admin") {<br> frmDemo.submit(); //提交<br> }<br> else {<br> return;<br> }<br> });</p> <p>EventUtil.addHandler(txtUID, 'keydown', function () {<br> var e = EventUtil.getEvent(); //Enter.keyCode = 13;<br> if (e.keyCode == 13) {<br> txtPWD.focus();<br> EventUtil.preventDefault(e);<br> }<br> });<br> div1 div2 div3