0
我正在使用一個下拉列表作爲導航選項在一個節中的頁面之間移動。我希望用戶能夠從下拉列表中進行選擇,當他們點擊開始時,讓他們將其帶到新頁面。如何使用jQuery .change事件導航到新頁面?
你可以看到它在它不完善的狀態here。
下面是HTML:
<form>
<label for="new-location">Select a Location</label>
<select name="new-location" id="new-location">
<option selected>Please select one</option>
<option value="http://www.google.com/">Google</option>
<option value="http://www.search.com/">Search.com</option>
<option value="http://www.dogpile.com/">Dogpile</option>
</select>
<input type="submit" value="Go" />
</form>
這裏是jQuery的我都試過了。但是,它不能按預期工作。
<script type="text/javascript">
$("#new-location").change(function() {
// simulates similar behavior as an HTTP redirect
window.location.replace($(this).val());
});
</script>
我希望在修改此功能以便正常工作方面提供一些幫助。
嗨傑克,我剛剛添加了代碼。它給了我這個網址:http://www.flowerwood.com/locations/loxley_alabama?new-location=http%3A%2F%2Fwww.google.com%2F但不加載新頁面。請看看並試一試。 – fmz
你在那個網頁上的代碼是錯誤的 - 你打電話給$(「#new-location」)。onchange而不是$(「#new-location」)更改 –
嗨傑克,我糾正了代碼,但它仍然沒有加載新的頁面。 – fmz