简体   繁体   English

Onchange选择不刷新

[英]Onchange select without refresh

When change value my page is refresh because i have to send value to query data but my selector doesn't show value when selected当更改值时,我的页面会刷新,因为我必须将值发送到查询数据,但我的选择器在选择时不显示值

<form name='active' action='' method='GET'>
<select class="form-control" id="section" name="section" onchange="list()" >
<option value="0"> - - Select All - - </option>
  <?php
       $section = $db->fetch();
       foreach ($section as $key => $v) {
        $section_name = $v['section'];
        echo "<option value='".$section_name."'>",$section_name,"</option>";
       }
?>                       

<script type="text/javascript">
  function list(){ 
      document.active.submit(); 
  }
</script>

For an option in a dropdown other than the first one to be selected on page load, you have to add the selected="selected" attribute to one of the <option> elements like so :对于除页面加载时要选择的第一个以外的下拉列表中的选项,您必须将selected="selected"属性添加到<option>元素之一,如下所示:

<select class="form-control" id="section" name="section" onchange="list()" >
  <option value="0"> - - Select All - - </option>
  <option value="1" selected="selected"> I'm selected </option>
  <option value="2"> I'm not selected </option>
</select>

In your case, it implies checking either the GET variable or the database value in your foreach loop to set the attribute accordingly.在您的情况下,这意味着检查 GET 变量或 foreach 循环中的数据库值以相应地设置属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM