Onclick导航

时间:2015-01-13 20:25:42

标签: javascript

<select id="drp" value="maindrp" name="maindrp">
        <option>Select Categories</option>
        <option id="vhc" value="mainvhc">Vehicles</option>
        <option id="re" value="mainre">Real Estate</option>
        <option id="pt" value="mainpt">Pets</option>
        <option id="el" value="mainel">Electronics</option>
        <option id="cl" value="maincl">Clothing&Jewerly</option>
        <option id="co" value="mainco">Computers&Network</option>
    </select>
    <input type="text" placeholder="Search" id="msc">
        <input type="submit" value="Go" id="go" onclick= "go();">


function go() { 
    if (document.getElementById("vhc")) { 
        window.location="vehicles.php"; 
    }else if (document.getElementById("re")) { 
        window.location="realestate.php"; } } 

我想通过点击功能下拉按钮从所选项目导航。 有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:1)

试试这个,您需要<select>代码

的值
function go(){
  var sel = document.getElementById('drp').value; // get value of <select>
  if(sel=='mainvhc')
    window.location.href='vehicles.php';
  ...
}