熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

javascript實現跳轉菜單的具體方法

2022-06-13   來源: JSP教程 

  傳統

  

  這裡要做的是省略Go There按鈕選擇菜單項後直接跳轉

  

  Html代碼

復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "//WC//DTD XHTML Transitional//EN" "
<html xmlns="
<head> 
<meta httpequiv="ContentType" content="text/html; charset=utf" /> 
<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="topichtml">topic</option> 
    <option value="topichtml">topic</option> 
    <option value="topichtml">topic</option> 
    <option value="topichtml">topic</option> 
    <option value="topichtml">topic</option> 
  </select> 
  <!當浏覽器不支持javascript或者禁用腳本運行時被調用
 <noscript> 
    <input type="submit" value="Go There!"/> 
 </noscript> 
</form> 
</body> 
</html> 

  
Javascript腳本

復制代碼 代碼如下:

  
windowonload=initForm; 
//防止頁面緩存無法觸發onload  
windowonunload=function(){} 
    function initForm(){ 
        documentgetElementById("newLocation")selectIndex=
        documentgetElementById("newLocation")onchange=jumpPage; 
        } 
    function jumpPage(){ 
        var newLoc=documentgetElementById("newLocation"); 
        var newPage=newLocoptions[newLocselectedIndex]value; 
        if (newPage!=""){ 
            windowlocation=newPage; 
            } 
        } 


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20533.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.