JavaScript 小技巧(第一集)

**第一集 如何用滑鼠控制Web页面

** 在这一部分首先要为你展示的JavaScript特性是将你的滑鼠移到这个不同颜色的连结上面,此时看看浏览器下的状态列有何结果,然后这样的功能我们可以与JavaScript的功能相结合。怎样做到的呢 以下就是这一个连结的作法:
<a href="tpage.htm" onMouseOver="window.status='Just another stupid link...'; return true">
在这儿你只要在传统 <a> 的标签中加入 onMouseOver 的 method 就可达成你要的效果了。这里的 window.status 是用来让你可以在 WWW 浏览器的状态列上显示一些讯息用的。

在语法中,你可以看到讯息部分是用 ' 括起来的部分,而非以 " 括起来。在讯息部分结束之后,必须加上 ; return true。好了,利用以上的特性可以很简单的完成第二个连结的例子,相当简单。以onMouseOver 的 method ,然后配合事件发生时去呼叫函数 hello() 就行了,不再多加解释了。

作法如下

<html>
<head>
<script language="LiveScript">
<!-- Hiding
function hello() {
alert("哈罗!");
}
</script>
</head>
<body>
<a href="" onMouseOver="hello()">link</a>
</body>
</html>

Published At
Categories with 网页设计
comments powered by Disqus