onmouseover事件显示连接描述
2013-11-22 12:32
141 查看
定义几个超连接。鼠标放上去时显示对他们的描述。
用到了onmouseover和onmoouseout两个事件。html代码如下
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Discriptive Links</title>
</head>
<body >
<h1>Discriptive Links</h1>
<p>Move the mouse pointer over one of these links to view a description</p>
<ul>
<li><a id="order" href="order.html">order</a></li>
<li><a id="email" href="email.html">email</a></li>
<li><a id="complain" href="complain.html">complain</a></li>
</ul>
<h2 id="description"></h2>
<script type="text/javascript" src="test2.js"></script>
</body>
</html>
test2.js代码如下
function cleardesc(){
d=document.getElementById("description");
d.innerHTML="";
}
function hover(e){
if(!e){
var e =window.event;
}
whichlink=e.target.id?e.target.id:e.srcElement.id;
if(whichlink=="order"){desc="order a product."}
if(whichlink=="email"){desc="send us a message."}
if(whichlink=="complain"){desc="insult us,our products,our families."}
d=document.getElementById("description");
d.innerHTML=desc;
}
orderlink=document.getElementById("order");
orderlink.onmouseover=hover;
orderlink.onmouseout=cleardesc;
emaillink=document.getElementById("email");
emaillink.onmouseover=hover;
emaillink.onmouseout=cleardesc;
complainlink=document.getElementById("complain");
complainlink.onmouseover=hover;
complainlink.onmouseout=cleardesc;
其中对连接绑定事件那9行代码可以用jquery批量加。这里就先不研究了。
有个细节要注意的是,并没有写传递event这个值,方法里就直接可以接受并赋值给e。挺好。
记得有一次我直接在html元素里写 onclick="testEvent(e)"传不过去事件对象。改成onclick="testEvent(event)"就传过去了。html中定义定义时间传递event对象时参数必须为event吗?待考证。
用到了onmouseover和onmoouseout两个事件。html代码如下
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Discriptive Links</title>
</head>
<body >
<h1>Discriptive Links</h1>
<p>Move the mouse pointer over one of these links to view a description</p>
<ul>
<li><a id="order" href="order.html">order</a></li>
<li><a id="email" href="email.html">email</a></li>
<li><a id="complain" href="complain.html">complain</a></li>
</ul>
<h2 id="description"></h2>
<script type="text/javascript" src="test2.js"></script>
</body>
</html>
test2.js代码如下
function cleardesc(){
d=document.getElementById("description");
d.innerHTML="";
}
function hover(e){
if(!e){
var e =window.event;
}
whichlink=e.target.id?e.target.id:e.srcElement.id;
if(whichlink=="order"){desc="order a product."}
if(whichlink=="email"){desc="send us a message."}
if(whichlink=="complain"){desc="insult us,our products,our families."}
d=document.getElementById("description");
d.innerHTML=desc;
}
orderlink=document.getElementById("order");
orderlink.onmouseover=hover;
orderlink.onmouseout=cleardesc;
emaillink=document.getElementById("email");
emaillink.onmouseover=hover;
emaillink.onmouseout=cleardesc;
complainlink=document.getElementById("complain");
complainlink.onmouseover=hover;
complainlink.onmouseout=cleardesc;
其中对连接绑定事件那9行代码可以用jquery批量加。这里就先不研究了。
有个细节要注意的是,并没有写传递event这个值,方法里就直接可以接受并赋值给e。挺好。
记得有一次我直接在html元素里写 onclick="testEvent(e)"传不过去事件对象。改成onclick="testEvent(event)"就传过去了。html中定义定义时间传递event对象时参数必须为event吗?待考证。
相关文章推荐
- 鼠标onmouseover,onmouseout事件动态创建DIV 显示图片
- (10)行颜色间隔显示并高亮:鼠标事件onmouseover、onmouseout
- VB中adodc与Adodb版本冲突(显示为“过程声明与同名事件或过程的描述不匹配”)
- Ubuntu使用PPPoe上网后显示“设备未托管”(无有线网络连接)
- struts2文件上传失败后不跳到input而显示连接被重置
- asp.net绑定checkboxlist--------jquery绑定click事件,获取checkbox的value和显示值
- 用onclick事件实现文章可用大字体中字体小字体显示网页教程
- 鼠标放上列表后显示图片和描述效果
- 鼠标事件---显示隐藏的菜单
- 数据库的连接及数据读取,显示操作
- 解决 ERROR - ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
- 我的手机是三星GTS-5570,现在开机就显示com.android.phone进程意外停止,连网络也不能连接
- 解决 ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
- 宽带连接新建提示711,宽带连接显示不可用,找不到设备,拨号提示797错误
- Zookeeper命令行操作(常用命令;客户端连接;查看znode路径;创建节点;获取znode数据,查看节点内容,设置节点内容,删除节点;监听znode事件;telnet连接zookeeper)
- ORA-12514:TNS:监听程序当前无法识别连接描述符中请求的服务
- UGUI_背包系统的自动化布局,选中格子特殊显示,物品描述跟随
- 远程桌面问题,连接后马上断开,并显示“远程计算机已结束连接”或者不显示
- android监听虚拟键盘隐藏和显示事件