想做一个下拉菜单的脚本,根据前面所选的内容,点击GO图片后,跳转到对应的链接上。以下是我的代码,但是点击GO图片后,总是跳转到第一个选项的链接。请帮忙看看哪出问题了。谢谢
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Demos</title>
<style type="text/css">body{font-size:12px;font:12px Arial, Helvetica, sans-serif;}.pro_select{
width:210px;
height:26px;
float:left;
margin-top: 0;
margin-right: 1px;
margin-bottom: 0;
margin-left: 1px;
border-color: #C6E321;
top: 2px;
}#pro_qty,#a1,#a2,#a3{
float:left;border-color: #C6E321height:20px;
width:190px;
padding-left:4px;
line-height:24px;
background-repeat: no-repeat;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #C6E321;
border-right-color: #C6E321;
border-bottom-color: #C6E321;
border-left-color: #C6E321;
background-color: #FFFFFF;
}#pro_qty_but,#b1,#b2,#b3{float:left;width:22px;cursor:pointer;}#qty_items,#c1,#c2,#c3{clear:left;width:193px;border-right:1px solid #C6E321;border-bottom:1px solid #C6E321;border-left:1px solid #C6E321;position:absolute;z-index:80;}.qty_items_out {background-color:#FFFFFF;padding-left:2px;cursor:pointer;line-height:18PX;z-index:1;}.qty_items_over{background-color:#CCCCCC;padding-left:2px;cursor:pointer;line-height:18PX;}.clear{clear:left;}a{text-decoration:none;color: #000;}</style>
</head>
<body>
<table width="849" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="3" rowspan="2">&nbsp;</td>
    <td width="36" height="40" rowspan="2">&nbsp;</td>
    <td width="523" valign="top">&nbsp;</td>
    <td width="287" height="40" rowspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td height="45" bgcolor="#FFFFFF" weight="190"><div class="pro_select ">
      <div id="pro_qty">New Test</div>
      <div class="id" onclick="show_select('pro_qty','pro_qty_but','qty_items','qty')" > <img src="BGImages/03.jpg" width="20" height="24" style="cursor:pointer;margin-left:-20px; margin-top:1px;" /></div>
      <div class="clear"></div>
      <div id="qty_items" style="display: none">
        <div class='qty_items_out'><a href="http://www.sohu.com">New Test</a></div>
        <div class='qty_items_out'><a href="http://www.baidu.com">Ceshi</a></div>
        <div class='qty_items_out'><a href="http://www.google.com.hk">googceshi</a></div>
        <div class='qty_items_out'><a href="http://www.163.com">163ceshi</a></div>
        <div class='qty_items_out'><a href="http://www.sina.com.cn">Sinaceshi</a></div>
        <div class='qty_items_out'><a href="http://www.kaixin001.com">Kaixinceshi</a></div>
        <div class='qty_items_out'><a href="http://www.ali213.net">gameceshi</a></div>
        <div class='qty_items_out'><a href="http://www.yahoo.com">yahooceshi</a></div>
      </div>
      <table width="210" border="0">
        <tr> </tr>
      </table>
      <p>&nbsp;</p>
    </div>
        <a href="#" onclick="aaa();"><img src="bgimages/Go.jpg" width="45" height="20" border="0"  align="left"/></a>
        <form id="form1" name="form1" method="post" action="">
          <input name="qty" type="hidden" id="qty" value="1" />
          <input name="qty2" type="hidden" id="d1" value="1" />
          <input name="qty2" type="hidden" id="d2" value="1" />
          <input name="qty2" type="hidden" id="d3" value="1" />
      </form></td>
  </tr>
  <tr>
    <td width="3" height="81">&nbsp;</td>
  </tr>
  <tr>
    <td width="3" height="15" rowspan="-2" valign="bottom">&nbsp;</td>
  </tr>
  <tr>
    <td width="3">&nbsp;</td>
  </tr>
</table>
</body>
<script language="javascript" type="text/javascript">var flag = true;function show_select(input,btn,option,value){var inputobj=document.getElementById(input);var btnobj=document.getElementById(btn);var optionobj=document.getElementById(option);var valueobj=document.getElementById(value);function chk() {if (flag) {document.getElementById(option).style.display = 'none';}}// 50flagoptionobj.onmouseout = function() {setTimeout(chk, 50);}optionobj.style.display=optionobj.style.display==""?"none":"";for (var j=0;j<optionobj.childNodes.length;j++){// optionobj.focus();optionobj.childNodes[j].onmouseover=function (){this.className="qty_items_over";// flagflag = false;};optionobj.childNodes[j].onmouseout=function (){this.className="qty_items_out";// flagflag = true;};optionobj.childNodes[j].onclick=function () {inputobj.innerHTML=this.innerHTML;valueobj.value=this.innerHTML;optionobj.style.display="none";a = this.getElementsByTagName('a')[0];h = a.href;//window.location.href =h;};}};function aaa(){ var optionobj=document.getElementById("qty_items"); a = optionobj.getElementsByTagName('a')[0]; h = a.href; window.location.href =h;}</script>

解决方案 »

  1.   

    function aaa() {        var optionobj = document.getElementById("qty_items");       a = optionobj.getElementsByTagName('a')[0];
            alert(a);
             h = a.href;        window.location.href = h;    }
    这里你自己限定了a的元素啊
      

  2.   


       function aaa() {
             window.location.href = h;
        }因为你前面onclick已经把选中的赋给了h,这里直接引用h就行了