0

如果我的页面显示:

“代码不正确,请重试”

那么我的 URL 重定向应该是:

http://site.site.co.uk/index.php#contact

我想使用 Jquery,但不确定如何在页面上检查这个然后重定向?

我试过了:

$("div#contact-form:contains('Code incorect please try again')").attr("location","http://site.site.co.uk/index.php#contact");

4

4 回答 4

2

您可以使用以下内容:

if ($("#contact-form").is(":contains('Code incorect please try again')")) {
    window.location.href = "http://site.site.co.uk/index.php#contact";
}
于 2012-06-26T09:11:20.900 回答
1

如果它是一个内部服务器的东西(或者你是精确的并且任何页面说无论如何都应该被重定向),js不会帮助你。为此,您需要查看 Web 服务器 - 如果想到 apache、mod_proxy,或者其他一些模块可以评估 apache 的 req/res 链并从那里开始(如果它像 mod_perl,这不是很有趣) . iirc,你可以用 nginx 做类似的事情。

但是,如果这是一个 js 事件,请将其绑定并更改 window.location 或其他任何内容。

于 2012-06-26T09:10:47.080 回答
1

这样做: -

if ($("div#contact-form:contains('Code incorect please try again')").length == 1)
    window.location.replace("http://site.site.co.uk/index.php#contact"); 

参考演示

于 2012-06-26T09:18:41.460 回答
0
var myDiv = $('div#contact-form:containt('Code incorrect please try again'));

if(myDiv.length === 0) {
    location = "http://site.site.co.uk/index.php#contact";
}
于 2012-06-26T09:10:44.797 回答