【问题标题】:bootstrap data-dismiss="alert" -- and redirect the other pagebootstrap data-dismiss="alert" -- 并重定向另一个页面
【发布时间】:2015-07-28 12:33:53
【问题描述】:

我有以下带有 BS 代码的 PHP 和 HTML:

<?php if (isset($_GET['register']) && $_GET['register'] == 'get') {?>
    <div class="alert alert-danger success">
        <button type="button" class="close" data-dismiss="alert" onclick="return refresh('index.php')">×</button>
        <strong>The register must be done with GET!</strong>
    </div>
<?php }?>

通过 $_GET superglobal 将错误从 register.php 发送到 index.php,该错误在 index.php 中使用上述代码“捕获”。此时我的网址是index.php?register=get。我想要两件事:

  1. 使用 class="alert" 关闭 div(已经完成)
  2. 当按下 alert-danger 消息的小“x”时,重新加载页面,这样 ?register=get 就消失了,URL 变成了简单的:index.php

到目前为止我已经尝试过:

  1. 使用“onclick” HTML 属性调用它的 JS 函数

    function refresh(page){ return window.location.href(page); }

  2. &lt;button type="button" class="close" data-dismiss="alert" id="close1"&gt;×&lt;/button&gt;

我使用以下 jquery 代码:

$("#close1").on("click", function () {
    window.location.href("http://localhost/ampera/src/supervizor/app/sef_locatie_nou.php");
});

我对 jquery 代码使用了绝对路径和相对路径,都没有工作。并且代码只会关闭警报危险消息,但不会根据需要重新加载页面。

【问题讨论】:

  • 您使用的是哪个 jquery 版本?
  • jquery-1.11.3.min.js

标签: javascript php jquery html twitter-bootstrap


【解决方案1】:

尝试 window.open :

window.open("http://localhost/ampera/src/supervizor/app/sef_locatie_nou.php", "_self");

演示:

http://jsfiddle.net/Rj9bR/54/

【讨论】:

    【解决方案2】:

    试试这个

    $("#close1").on("click", function () {
        location.assign("http://localhost/ampera/src/supervizor/app/sef_locatie_nou.php");
    });
    

    【讨论】:

    • 不,我已经尝试过了,而且......这是更糟糕的情况......因为当我按下“x”时,将使用相同的警报消息和相同的 URL 重新加载页面。
    • 从 html 中删除这个 onclick="return refresh('index.php')",然后为按钮添加 id='close1' 然后使用 jquery
    • 然后试试 location.assign(url);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多