HTML-事件(Event)的总结

HTML 与 JavaScript 的交互是通过事件来处理的,当用户或浏览器操纵页面时。事件就会发生。

使用事件来执行 JavaScript 编码的响应

每个HTML元素有一定的事件可以触发 JavaScript 代码

比如: 加载页面、点击按钮、关闭窗口

介绍几个常见的事件类型

onclick 事件类型

这是最常用的事件类型,当用户点击鼠标左按钮。你可以把你的验证、警告等反对这个事件类型。

支持该事件的 HTML 标签:

<a>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>, <button>, 
<caption>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>, 
<form>, <h1> to <h6>, <hr>, <i>, <img>, <input>, <kbd>, <label>, <legend>, 
<li>, <map>, <object>, <ol>, <p>, <pre>, <samp>, <select>, <small>, <span>, 
<strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>, <th>, 
<thead>, <tr>, <tt>, <ul>, <var>

支持该事件的 JavaScript 对象:

button, document, checkbox, link, radio, reset, submit

具体实例

<script>
    function sayHello() {
       alert("Hello World")
    }
</script>

<body>
    <input type="button" onclick="sayHello()" value="Say Hello" />
</body>

onmouseover/onmouseout

nmouseover: 事件发生时,当你把你的鼠标在任何元素上时, onmouseover 事件发生
onmouseout: 当你把鼠标从该元素移开时,onmouseout 事件发生

支持该事件的 HTML 标签:

<a>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>, <button>, 
<caption>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>, 
<form>, <h1> to <h6>, <hr>, <i>, <img>, <input>, <kbd>, <label>, <legend>, 
<li>, <map>, <ol>, <p>, <pre>, <samp>, <select>, <small>, <span>, <strong>, 
<sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>, <th>, <thead>, 
<tr>, <tt>, <ul>, <var>

支持该事件的 JavaScript 对象:

layer, link
<html>
    <head>
        <script>
            function mouseOver()
            {
                alert("on mouse over")
            }
        </script>
    </head>

    <body>
        <img src="/i/eg_mouse2.jpg" onmouseover="mouseOver()" />
    </body>
</html>

HTML 4 标准事件

执行以下脚本显示一个Javascript函数。

事件类型何时执行Javascript函数
onchangescript当元素改变时
onsubmitscript确认按钮被点击时
onresetscript当表单被重置时
onselectscript当元素被选中时
onblurscript当元素失去焦点时
onfocusscript当元素成为焦点时
onkeydownscript某个键盘按键被按下时
onkeypressscript某个键盘按键被按下并松开时
onkeyupscript某个键盘按键被松开时
onclickscript当鼠标单击时
ondblclickscript当鼠标双击时
onmousedownscript鼠标按钮被按下时
onmousemovescript鼠标被移动时
onmouseoutscript鼠标从某元素移开时
onmouseoverscript鼠标移到某元素之上时
onmouseupscript鼠标按键被松开时
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值