网页链接说明的JS程序
2015-09-29 17:43
561 查看
通过even对象t获取对象属性(srcElement或target属性)的使用和将事件设置为属性的使用,制作网页链接说明的小JS demo
//在Internet Explorer的event属性中event.srcElement代表元素出现的对象
//在Netscape和Firefox的event属性中event.target代表元素出现的对象
<!document html>
<body>
<h1>为网页链接添加说明</h1>
<center>
<a href="http://baidu.com" id="ex1">example1</a><br/>
<a href="http://sogou.com" id="ex2">example2</a><br/>
<a href="http://huohu.com" id="ex3">example3</a><br/>
<h2 id="description"></h2><br/>
</center>
<script language="javascript" type="text/javascript">
function hover(e){
if(!e) var e = window.event;
whichlink = (e.target) ? e.target.id : e.srcElement.id; //whichlink获取元素的对象
if(whichlink=="ex1") desc="示例1";
else if(whichlink=="ex2") desc="示例2";
else if(whichlink=="ex3") desc="示例3";
t = document.getElementById("description");
t.innerHTML = desc;
}
function cleardesc(){
t = document.getElementById("description");
t.innerHTML = "";
}
alink = document.getElementById("ex1");
alink.onmouseover = hover; //将事件设置为属性,注意onmouseover都是小写。
alink.onmouseout=cleardesc;
blink = document.getElementById("ex2");
blink.onmouseover = hover;
blink.onmouseout=cleardesc;
clink = document.getElementById("ex3");
clink.onmouseover = hover;
clink.onmouseout=cleardesc;
</script>
</body>
</html>
//在Internet Explorer的event属性中event.srcElement代表元素出现的对象
//在Netscape和Firefox的event属性中event.target代表元素出现的对象
<!document html>
<body>
<h1>为网页链接添加说明</h1>
<center>
<a href="http://baidu.com" id="ex1">example1</a><br/>
<a href="http://sogou.com" id="ex2">example2</a><br/>
<a href="http://huohu.com" id="ex3">example3</a><br/>
<h2 id="description"></h2><br/>
</center>
<script language="javascript" type="text/javascript">
function hover(e){
if(!e) var e = window.event;
whichlink = (e.target) ? e.target.id : e.srcElement.id; //whichlink获取元素的对象
if(whichlink=="ex1") desc="示例1";
else if(whichlink=="ex2") desc="示例2";
else if(whichlink=="ex3") desc="示例3";
t = document.getElementById("description");
t.innerHTML = desc;
}
function cleardesc(){
t = document.getElementById("description");
t.innerHTML = "";
}
alink = document.getElementById("ex1");
alink.onmouseover = hover; //将事件设置为属性,注意onmouseover都是小写。
alink.onmouseout=cleardesc;
blink = document.getElementById("ex2");
blink.onmouseover = hover;
blink.onmouseout=cleardesc;
clink = document.getElementById("ex3");
clink.onmouseover = hover;
clink.onmouseout=cleardesc;
</script>
</body>
</html>
相关文章推荐
- JQuery1——基础($对象,选择器,对象转换)
- Android学习笔记(二九):嵌入浏览器
- Android java 与 javascript互访(相互调用)的方法例子
- JavaScript演示排序算法
- javascript实现10进制转为N进制数
- 2019年开发人员应该学习的8个JavaScript框架
- HTML中的script标签研究
- 对一个分号引发的错误研究
- 异步流程控制:7 行代码学会 co 模块
- ES6 走马观花(ECMAScript2015 新特性)
- JavaScript拆分字符串时产生空字符的原因
- Canvas 在高清屏下绘制图片变模糊的解决方法
- IE8开发人员工具教程(二)
- 在flex中执行一个javascript方法的简单方式
- Flex结合JavaScript读取本地路径的方法
- PowerShell中执行Javascript的方法示例
- javascript asp教程第六课-- response方法
- javascript asp教程More About Recordsets
- javascript asp教程第十二课---session对象