当前位置导航:炫浪网>>网络学院>>网页制作>>ASP教程

动态创建下拉菜单

  <html>
<head>

<title>动态下拉菜单</title>
<style>
SELECT.smallSel
{
  BACKGROUND-COLOR: white;
  COLOR: #000080;
  FONT-SIZE: 9pt
}
</style>
<script language=javascript>
<!-- hide from old browsers...

/*   动态下拉菜单 -- written by Taylor Chen (Taylor999)
    如果您发现任何问题,请E-mail给我,[email protected]
*/


var info = new Array(
  "杂文*弥天大谎的背后|院士相当于副省级?|为教育打几个激灵|预算黑洞一例|官不贵,民不贱|省了麻烦|

轿车不如轿子说|这回确是个别|血和泪构成的笑话|给张艺谋松绑吧!",
  "生活随笔*木兰漂亮吗?|一张旧车票|酒味杂谈|时空隧道|最后捞一把",
  "文选*家庭也要有民主|“待遇”的联想|“农民”不是形容词|只多一点点",
  "读者*当代“士子”之悲|谈程序|厅长说与百姓说|其实很高明");

var infoA=new Array(
  "焦点话题*安徽:国企领导可以超龄任职|新世纪怎么花钱|武汉:企业将告别行政级别",
  "读者书屋*欲火",
  "品味园*破译“中国人之谜”不妨读读《闲话中国人》|请客吃饭乐无穷|走动走动向上浮动|文人也当谋富

|做并享受着———与白岩松笑谈摭拾|比谁写得厚",
  "环球采风*法国建成绿色学校|俄罗斯第一夫人温情谈恋史|法国人才外流有原因|德国电脑人才可破例|德

国慕尼黑啤酒节",
  "人物春秋*我所知道的胡乔木|自信些,迎接全球化|红与黑");
var mywork= new Array("",info,infoA);
/************************************************************************************************

******/

function stringSplit ( string, delimiter ) {
  if ( string == null || string == "" ) {
    return null;
  } else if ( string.split != null ) {
    return string.split ( delimiter );
  } else {
    var ar = new Array();
    var i = 0;
    var start = 0;
    while( start >= 0 && start < string.length ) {
       var end = string.indexOf ( delimiter, start ) ;
       if( end >= 0 ) {
         ar[i++] = string.substring ( start, end );
         start = end+1;
       } else {
         ar[i++] = string.substring ( start, string.length );
         start = -1;
       }
    }
    return ar;
  }
}
/************************************************************************************************

******/
var menu1 = new Array();
var menu2 = new Array();
/************************************************************************************************

******/
function createMenus ( wh ) {
  var infoname = new Array();
  infoname=mywork[wh];
  for ( var i=0; i < infoname.length; i++ ) {
    menu1[i] = stringSplit ( infoname[i], '*' );
    menu2[i] = stringSplit ( menu1[i][1], '|' );
  }

  var author = document.myForm.main;
  var book = document.myForm.title;

  author.length = infoname.length;
  book.length = menu2[0].length;
  for ( var i=0; i < infoname.length; i++ ) {
     author.options[i].value = menu1[i][0];
     author.options[i].text  = menu1[i][0];
  }
  document.myForm.main.selected = 0;
  for (var x=0; x < menu2[0].length; x++) {
     book.options[x].text = menu2[0][x];
     book.options[x].value = menu2[0][x];
  }     
  document.myForm.title.selected = 0;
}

/************************************************************************************************

******/

function updateMenus ( what ) {
  var sel = what.selectedIndex;

  if ( sel >= 0 && sel < menu1.length )
    var temp = menu2[sel];
  else
    var temp = new Array ();
   
  what.form.title.length = temp.length;

  for ( var i = 0; i < temp.length; i++ ) {
    what.form.title.options[i].text = temp[i];
    what.form.title.options[i].value = temp[i];
  }
  what.form.title.selected=0;
}
// end of hiding -->
</script>
</head>

<body background="" bgcolor="#ffffff" text="#400040" link="#ff0080" vlink="#ff8080"

alink="#ff0000">
<center><h1>动态下拉菜单</h1></center>

<form name=myForm action=test2.asp method=post><p>
分类:&nbsp;
<select name=my size=1 onchange="createMenus(document.myForm.my.selectedIndex)" class="smallsel">
<option selected></option>
<option value="info">杂文报</option>
<option value="infoA">书刊报</option>
</select>
<p>
作者: &nbsp;<select name="main" size=1 onChange="updateMenus(this)" class="smallsel">
<option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp

;&nbsp;&nbsp;&nbsp;&nbsp;
<option>
<option>
</select>
<p>
标题:&nbsp;
<select name="title" size=1 class="smallsel">
<option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp

;
<option>
<option>
</select>
<input type=button value=Submit onclick="parent.location.href='http://www.hebeidaily.com.cn'">
</form>
</body>
</html>

 
相关内容
赞助商链接