I have a conditional statement that I need to add a redirect depending on what conditional statement is met and I have no clue how to proceed. I am using the jquery.if plugin as well.
<div id="load"></div>
<script type="text/javascript">
// ** DEMO 1 *************
var b1 = "Wholesale";
$("#load")
.IF(b1 == "Wholesal开发者_开发百科e")
.html ("window.location.href = 'http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery';")
.ELSE()
.ENDIF()
</script>
I have no idea why you're trying to write logic flow as if they were suddenly jQuery selectors.
if (b1 == "Wholesale") {
$("#load").html("window.location.href = 'http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery';")
};
And do you really want to be writing that script into HTML? Why don't you just run it if you want to perform a redirect?
if (b1 == "Wholesale") {
window.location.href = 'http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery';
};
You don't need jQuery to redirect via the clientside. I'd suggest using plain old vanilla JavaScript via the DOM.
window.location.href = "http://stackoverflow.com";
should do the trick if all you need is a redirect.
The above is really confusing. That said, jQuery's not going to do much for you in this case. Also given that you don't really have an else statement to make I don't think you need it. Here's all you really need to do:
if(b1 == "Wholesale") {
// code to be executed if condition is true
window.location.replace("http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery");
);
精彩评论