十种JavaScript事件处理的使用方法

1. onFocus:在用户为了输入而选择select、text、textarea等时
< html >

< head >

</ head >

< body >

< form  name ="test" >

< input  type ="text"  name ="userName"  value ="abc"  onFocus ="JavaScript:alert(document.test.userName.value);" >

</ form >

</ body >

</ html >
 
2. onBlur:在select、text、password、textarea失去焦点时
< html >

< head >

</ head >

< body >

< form  name ="test" >

< input  type ="text"  name ="userName"  value ="abc"  onblur ="JavaScript:alert(document.test.userName.value);" >



</ form >

</ body >

</ html >

3. onChange:在select、text、textarea的值被改变且失去焦点时
< html >

< head >

</ head >

< body >

< form  name ="test" >

< input  type ="text"  name ="userName"  value ="abc"  onChange ="JavaScript:alert(document.test.userName.value);" >

</ form >

</ body >

</ html >

4. onClick:在一个对象被鼠标点中时(button,checkbox,radio,link,reset,submit,text,textarea等)
< html >

< head >

</ head >

< body >

< img  src ="xsd.jpg"  onclick ="alert('ok');" ></ img >

</ body >

</ html >

5. onLoad:出现在一个文档完成对一个窗口的载入时
< html >

    
< head >

    
</ head >

    
< body  onLoad ="javascript:alert('hello');"  onUnload ="javascript:alert('bye-bye');" >

        nihao

    
</ body >

    

</ html >

6. onUnload:当用户退出一个文档时
< html >

    
< head >

    
</ head >

    
< body  onLoad ="javascript:alert('hello');"  onUnload ="javascript:alert('bye-bye');" >

        nihao

    

    
< form  name ="test" >

        
< input  type ="text"  name ="t"  value ="hello"  onSelect ="javascript:alert('');" >

        
< select  name ="se" >

            
< option  value ="0" > hehe </ option >

            
< option  value ="1" > hehe </ option >

        
</ select >

    
</ form >

    
</ body >

</ html >

7. onMouseOver:鼠标被移动到一个对象上时
< html >

< head >

</ head >

< body >

< img  src ="xsd.jpg"  onmouseover ="alert('over')"  onmouseout ="alert('out')" ></ img >

</ body >

</ html >

8. onMouseOut:鼠标从一个对象上移开时
代码同上

9. onSelect:当form对象中的内容被选中时
< html >

< head >

</ head >

< body >

< form  name ="test" >

< input  type ="text"  name ="userName"  value ="SXT"  onSelect ="JavaScript:alert(document.test.userName.value);" >

</ form >

</ body >

</ html >

10. onSubmit:出现在用户通过提交按钮提交一个表单时
< html >

< head >

    
< script  type ="text/javascript" >

        
function check() {

            
if(document.test.t.value == ""{

                alert(
"空值");

                
return false;

            }


            
return true;

        }


    
</ script >

</ head >

< body >

< form  name ="test"  action ="1.htm"  onsubmit ="return check();" >

    
< input  type ="text"  name ="t" >

< input  type ="submit"  value ="ok" >

</ form >

</ body >

</ html >
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值