我想不提交表单的情况下,获取列表菜单的值,同时选择下拉菜单的值后,还能停留在所选择的那个值的页面
<select name="select" onchange="location.href='?select='+this.options[this.selectedIndex].value">
                  <option value="0">-------</option>
                     <?php
                     $db=db_connect();
                     $sql="select * from `title`";
                     $rs=$db->query($sql);
                     while($row=mysqli_fetch_array($rs))
 {
     ?>
                     <option value="<?=$row[id]?>">
                     <?=$row[title]?>
                     </option>
                     <?
                      }
                     ?>
          </select>
我的代码,可以传值,但传值后,下拉菜单里面的值会回滚,只能显示“-------”这个值的页面
怎样传值后,不会回滚。

解决方案 »

  1.   

    你这个功能很奇怪哦,呵呵下面的代码应该可以,也可以用JS或AJAX<select name="select" onchange="location.href='?select='+this.options[this.selectedIndex].value">
                      <option value="0">-------</option>
                         <?php
                         $db=db_connect();
                         $sql="select * from `title`";
                         $rs=$db->query($sql);
                         while($row=mysqli_fetch_array($rs))
                         {
                         ?>
                         <option value="<?=$row[id]?>" <?php if ($_GET['select'] == $row[id]) echo "selected";?>>
                         <?=$row[title]?>
                         </option>
                         <?
                          }
                         ?>
              </select>