How to make a page redirect using JavaScript?
This question already has an answer here:
Use:
window.location = "http://my.url.here";
Here's some quick-n-dirty code that uses jQuery to do what you want. I highly recommend using jQuery. It'll make things a lot more easier for you, especially since you're new to JavaScript.
<select id = "pricingOptions" name = "pricingOptions">
<option value = "500">Option A</option>
<option value = "1000">Option B</option>
</select>
<script type = "text/javascript" language = "javascript">
jQuery(document).ready(function() {
jQuery("#pricingOptions").change(function() {
if(this.options[this.selectedIndex].value == "500") {
window.location = "http://example.com/foo.php?option=500";
}
});
});
</script>
You can append the values in the query string for the next page to see and process. You can wrap them inside the link tags:
<a href="your_page.php?var1=value1&var2=value2">
You separate each of those values with the &
sign.
Or you can create this on a button click like this:
<input type="button" onclick="document.location.href = 'your_page.php?var1=value1&var2=value2';">
您可以使用location
对象来实现此目的。
location.href = "http://someurl";
链接地址: http://www.djcxy.com/p/1942.html
上一篇: 字符串不是窗口位置href上的函数