2009-02-24 97 views

回答

44

您不需要为此打包预先打包的脚本,只需几行代码即可。

// get your select element and listen for a change event on it 
$('#selectEl').change(function() { 
    // set the window's location property to the value of the option the user has selected 
    window.location = $(this).val(); 
}); 
8

我还没有测试过这个,但我认为它相当于您引用页面上的示例。

$(document).ready(function() { 
    $('#select').change(function() { 
     location.href = $(this).val(); 
    }); 
}); 

<select id="select"> 
    <option value="#">Select a location</option> 
    <option value="location.htm">Location</option> 
    <option value="other.htm">Other</option> 
</select> 
+0

在我看来,还是缺少一个')'? 无论如何...它不是jQuery,但是对于特别的东西来说,使用内联代码段更容易和更简单。