JS篩選器的製作

<select onchange="filterschool()"></select>
<select onchange="filterdirection()"></select>
<a onclick="filterhot(1)">最新</a>
<a onclick="filterhot(2)">最熱</a>
<script type="text/javascript">
  var schoolvalue = 0,
      directionvalue = 0,
      hotvalue = 0;
  function filterschool(){
      var obj = document.getElementById("filter-school");
      var index = obj.selectedIndex;
      schoolvalue = obj.options[index].value;
      creaturl()
      };
  function filterdirection(){
      var obj = document.getElementById("filter-direction");
      var index = obj.selectedIndex;
      directionvalue = obj.options[index].value;
      creaturl()
      }
  function filterhot(hot){
      hotvalue = hot;
      creaturl()
      }
  function creaturl(){
    url = schoolvalue+"/"+directionvalue+"/"+hotvalue;
    console.log(url)
  }
  </script>

界面:

兩個select標籤,學校、方向。

兩個a標籤分別是最熱、最新。

選擇任意,生成一個url,實現篩選效果。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章