鼠标事件

onclick 鼠标单击事件

<script>
       function con(){
       
       alert("xxx")
       
       }
       </script>
       <body>
       <button onclick='con()'>点击</button>
       
       </body>

当鼠标点击按钮时,将引用con()函数,从而弹出“xxx” 

 

ondblclick 鼠标双击事件

function con(){

alert("xxx")

}


<button ondblclick='con()'>双击</button>

当鼠标双击按钮时,将引用con()函数,从而弹出“xxx” 

 

oncontextmenu 鼠标右击事件

function con(){

alert("xxx")
}

<button oncontextmenu='con()'>右击</button>

(可阻止系统菜单弹出或自定义菜单)

当鼠标右击按钮时,将引用con()函数,从而弹出“xxx” 

 

onmouseover 鼠标滑过事件

<script>
       function con(){
       
       alert("xxx")
       
       }
       
       </script>
       <body>
       <button onmouseout='con()'>移开</button>
       
       </body>

 

 当鼠标移到按钮时,将引用con()函数,从而弹出“xxx”

 

onmouseup 鼠标点击松开

function con(){

alert("xxx")
}


<button onmouseup='con()'>点击松开</button>

 当鼠标松开按钮时,将引用con()函数,从而弹出“xxx”

 

onmouseout 鼠标移开事件

<script>
       function con(){
       
       alert("xxx")
       
       }
       
       </script>
       <body>
       <button onmouseout='con()'>移开</button>
       
       </body>

 当鼠标移开按钮时,将引用con()函数,从而弹出“xxx”

 

onmousedown 鼠标点击按下事件

function con(){

alert("xxx")
}

<button onmousedown='con()'>点击按下</button>

 当鼠标按下按钮时,将引用con()函数,从而弹出“xxx”

 

onmousemove 鼠标移动事件

function con(){

alert("xxx")
}

<button onmousemove='con()'>移动</button>

 当鼠标在按钮中移动时,将引用con()函数,从而弹出“xxx”

 

onfocus 光标聚焦事件

<script>
       function con(){
       
       alert("xxx")
       
       }
       
       </script>
       <body>
       <select name="career"onfocus="con()"> 
      <option>xx</option> 
      <option>xxx</option> 
       
    </select>
       
       </body>

当鼠标光标在框中时,将引用con()函数,从而弹出“xxx”

 

onblur 光标失焦事件

<script>
       function con(){
       
       alert("xxx")
       
       }
       function con2(){
       
       alert("xxx2")
       
       }
       </script>
       <body>
       
       
       <select name="career"onblur="con()"> 
      <option>xx</option> 
      <option>xxx</option> 
       
    </select>
       <button onblur='con2()'>离开</button>
       </body>

当光标在选择框时,若点击按钮,将引用con()函数,从而弹出“xxx”。当再点击选择框时,将换引用con2()函数,从而弹出“xxx2”

 

onselect 内容选中事件

<script>
       function con(){
       
       alert("xxx")
       
       }
       function con2(){
       
       alert("xxx2")
       
       }
       </script>
       <body>
       
       
       <textarea onselect='con()'>内容</textarea>
       <br />
       输入内容并选中:<input onselect='con2()'>
       </body>

当选中内容时,将会将引用con()函数,从而弹出“xxx”。当在第二栏输入并选中时,将引用con2()函数,弹出“xxx2”

 

onchage 文本框内容改变事件

<script>
       function con(){
       
       alert("xxx")
       
       }
       function con2(){
       
       alert("xxx2")
       
       }
       </script>
       <body>
       
       
       <textarea onchange='con()'>内容</textarea>
       <br />
       改变内容时:<input onchange='con2()'>
       </body>

改变内容,就会引用,弹出。

 

onload 加载事件

<script>
       function con(){
       
       alert("xxx")
       
       }
       function con2(){
       
       alert("xxx2")
       
       }
       function con3(){
       
       alert("xxx3")
       
       }
       </script>
       <body onload=con()>
       
       
       <textarea onselect='con3()'>内容</textarea>
       <br />
       改变内容时:<input onchange='con2()'>
       </body>

加载完body时,将引用,弹出“xxx”

 

卸载事件

<script>
       function con(){
       
       alert("xxx")
       
       }
      
       </script>
       <body onuload=con()>
 </body>

关闭或刷新网页时,将引用,弹出

 

编程练习-计算机

<!DOCTYPE html>  
<html>  
 <head>  
 <meta charset="utf-8">  
 <title></title>    
 <script type="text/javascript">  
  function count(){  
        var a = parseInt(document.getElementById("tex1").value);  
        var b = parseInt(document.getElementById("tex2").value);  
        var selectSign = document.getElementById("select").value;  
  
        switch (selectSign)  
        {  
        case '+': answer = a+b;break;  
        case '-': answer = a-b;break;  
        case '*': answer = a*b;break;  
        case '/': answer = a/b;       
        }  
        document.getElementById("fruit").value = answer;  
  }  
 </script>   
 </head>  
<body>  
  <input type="text" id="tex1" />  
  <select id="select">  
        <option value="+">+</option>  
        <option value="-">-</option>  
        <option value="*">*</option>  
        <option value="/">/</option>  
  </select>  
  <input type="text" id="tex2" />  
  <input type="button" value=" = " onclick="count()" />  
  <input type="text" id="fruit" onclick="count()" />  
</body>  
</html>

获取第一个输入框的值
获取第二个输入框的值
获取选择框的值
获取通过下拉框来选择的值来改变加减乘除的运算法则
设置结果输入框的值

posted on 2017-01-03 19:11  加号与剑豪  阅读(237)  评论(0编辑  收藏  举报

导航