这里有新鲜出炉的 Javascript 教程,程序狗速度看过来!
Javascript 是一种由 Netscape 的 LiveScript 发展而来的原型化继承的基于对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如 Perl,遗留的速度问题,为客户提供更流畅的浏览效果。
这篇文章介绍了 javascript 实现跳转菜单的具体方法,有需要的朋友可以参考一下
传统
这里要做的是,省略 Go There 按钮,选择菜单项后,直接跳转。
html 代码
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>
- 转移菜单
- </title>
- <script type="text/javascript" src="转移菜单.js">
- </script>
- </head>
- <body>
- <form>
- <select id="newLocation">
- <option selected="selected" value="">
- Select a topic
- </option>
- <option value="topic1.html">
- topic1
- </option>
- <option value="topic2.html">
- topic2
- </option>
- <option value="topic3.html">
- topic3
- </option>
- <option value="topic4.html">
- topic4
- </option>
- <option value="topic5.html">
- topic5
- </option>
- </select>
- <!--当浏览器不支持javascript或者禁用脚本运行时被调用-->
- <noscript>
- <input type="submit" value="Go There!" />
- </noscript>
- </form>
- </body>
- </html>
Javascript 脚本
- window.onload=initForm;
- //防止页面缓存,无法触发onload
- window.onunload=function(){}
- function initForm(){
- document.getElementById("newLocation").selectIndex=0;
- document.getElementById("newLocation").onchange=jumpPage;
- }
- function jumpPage(){
- var newLoc=document.getElementById("newLocation");
- var newPage=newLoc.options[newLoc.selectedIndex].value;
- if (newPage!=""){
- window.location=newPage;
- }
- }
来源: http://www.phperz.com/article/17/0416/279817.html