• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

JavaScript如何使用列表框实现url跳转的代码

JavaScript 水墨上仙 1383次浏览

JavaScript通过列表框实现url跳转的代码,在下拉框内输入相应的跳转项目和网址,选择其中一项,自动跳转到相应的网址

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>Combo Link w/ Description</title>
<style type="text/css">
<!--
label {
   display : block;
   color : #09f;
   border-bottom : 1px dashed #ccc;
   margin-bottom : .500em;
   padding-bottom : .300em;
   font-weight : bold;
   text-transform : uppercase; }
select {
   color : #506070;
   margin : 0 auto;
   text-align : center;
   border : 1px solid #ccc;
   letter-spacing : 2px;
   height : 28px;
   width : 300px;
   max-width : 300px; }
form div { position : relative; }
form {
   background-color : transparent;
   position : absolute;
   left : 3%;
   top : 3%; }
div#main {
   margin : 0 auto;
   min-height : 600px;
   padding : 0;
   width : auto; }
div#title {
   background-color : #fff;
   border : 1px solid #ccc;
   margin-top : 1em;
   padding : 1em;
   line-height : 1.4;
   min-height : 70px;
   letter-spacing : 1px;
   color : #506070; }
div#label {
   background-color : #f0fff0;
   margin : 0;
   max-width : 300px;
   min-height : 120px;
   padding : 1em;
   border : 1px solid #ccc;
 }
input#btn {
   border : 1px solid #ccc;
   color : #506070;
   margin-top : 1em;
   background-color : #fff;
   height : 28px;
   width : 50px;
     }
-->
</style>
<script type="text/javascript">
<!-- 
/* 
  COMBO Link Jumper - 
  Author : essential -
~ Profile : http://www.daniweb.com/forums/member383844.html -
~ Get instant solutions in your programming needs, visit : http://www.daniweb.com/
  ~ This notice must reamain intact for use.
*/
var formID = "formId"; // Specify your form id/name.
var divDesc = "title"; // Specify your div id, in where you want to show the text description.
var changeLoc = function( where ) {
   location.href = where;
   };
 
var navigate = function() {
var desc = [
/* Description / blurbs #1 */
"DANIWEB IT Discussion Community",
/* Description / blurbs #2 */
"Leading the Web to its full potential...",
/* Description / blurbs #3 */
"Full Web building tutorials - ALL Free!" ];
var div;
var form;
      try {
      div = document.getElementsByTagName("div")
      } catch( er ) {
      document.all.tags("div")
      } try {
      form = document.forms[ formID ];
      } catch( e ) {
      form = (( document.getElementById ) ? document.getElementById( formID ) : (( document.all ) ? document.all[ formID ] : document.layers[ formID ] ));
      }
   var index = form.sel.selectedIndex;
      div[ divDesc ].innerHTML = desc[ index ];
};
// -->
</script>
</head>
<body>
<div id="main">
<form id="formId" name="formId" action="." onsubmit="return false;">
<div id="label">
<label for="sel">Jump Box!</label> <select id="sel" name="sel" onchange="navigate();">
<option value="http://www.daniweb.com/">DANIWEB IT Community</option>
<option value="http://www.w3.org/">World Wide Web Consortium</option>
<option value="http://www.w3schools.com">W3Schools Online Tutorials</option>
</select>
<div>
<div id="title">DANIWEB IT Discussion Community</div><div><input type="button" id="btn" name="btn" onclick="changeLoc( formId.sel.options[ formId.sel.selectedIndex ].value );" value="GO!"></div></div>
</div>
</form>
</div>
</body>
</html>


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明JavaScript如何使用列表框实现url跳转的代码
喜欢 (0)
加载中……