指向我的其他网页的链接无效

时间:2015-10-19 19:43:16

标签: javascript php jquery html css

我正在尝试使用Twitter API for PHP并创建了一个部分,用户可以了解建议的人员跟随...

这是我的文件 getSuggestionSlug.php 的源代码:

<?php
include "methods.php";
oauthVerify();
if(isset($_GET["slug"]) && !empty($_GET["slug"]))
{
    $return = (array) getSuggestionSlug($_GET["slug"]);

}
else
{
    header("Location: getSuggestion.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Twitter Analytics</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link rel="stylesheet" href="http://bootswatch.com/paper/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <style>

        .showcase
        {

        }
        .showcase a
        {
            text-decoration: none !important;
        }
        .showcase:hover
        {
            background-color: #ededed;
            box-shadow: 0 0 20px #ddd;
            border-radius: 5px;
        }
    </style>
</head>
<body>
<nav class="navbar navbar-inverse">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index.php">Twitter Analyzer</a>
        </div>

        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
            <ul class="nav navbar-nav">
                <li><a href="sentimentAnalysis.php">Sentiment Analyzer<span class="sr-only">(current)</span></a></li>
                <li><a href="keywordLitics.php">Keyword Analytics</a></li>
                <li class="dropdown active">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">More&nbsp; &nbsp; &nbsp;<span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="makeFriend.php">Make Friends</a> </li>
                        <li class="active"><a href="getSuggestion.php">Get suggestions whom to make Friends</a></li>
                        <li class="disabled"><a href="#">Coming Soon...</a></li>
                        <li><a href="logout.php">Log Out</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>
<?php
$i = 0;
foreach($return["users"] as $user)
{
    if($i >= 12)
    {
        break;
    }
    echo "<div class='showcase col-md-3' id='{$user->screen_name}' data-name=\"{$user->name}\" style='margin-left: 100px; margin-top: 5%; height: 150px; text-align: center; vertical-align: middle; font-size: large; cursor: pointer; padding: 1%;' onmouseover='showControls( \"{$user->name}\", \"{$user->screen_name}\" );'>" . $user->name . "</div>";
    $i = $i + 1;
}
?>
<script src="script.js"></script>
<script>
    $(".showcase").on("mouseleave", function(){$(".showcase").attr("style", "margin-left: 100px; margin-top: 5%; height: 150px; text-align: center; vertical-align: middle; font-size: large; cursor: pointer; padding: 1%;"); $("button").remove();});
</script>
</body>
</html>

可以在我的网站here找到实时示例。

虽然我的 script.js 减少到相关部分,但如下所示:

var showControls = function(name, screen_name){
    console.log(name + " " + screen_name);
    $("#" + screen_name).attr("style", "margin-left: 100px; margin-top: 5%; height: 150px; font-size: large; cursor: pointer; padding: 1%;");
    $("#" + screen_name).html(name + "<br /><br /><a href='userShow.php?screen_name=" + screen_name + "'><button class='btn btn-primary'>Get Details</button></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='makeFriend.php?screen_name=" + screen_name + "'><button class='btn btn-primary'>Make Friend</button></a>")
};

我的问题是,悬停在框上方时出现的按钮不会打开任何链接,我使用<a>标记专门解决了这个问题,我也尝试使用window.location同样的结果

关于它为什么会发生的任何想法以及如何解决它?

1 个答案:

答案 0 :(得分:0)

与鼠标悬停在按钮上时多次调用函数showControls这一事实有关。每次你这样做,它都会摧毁并重新创建按钮。

作为一个例子试试这个。它只在第一次创建控件。在这种情况下,它可以工作(一旦反正)。

var first = true;
var showControls = function(name, screen_name){
    if(first) {
        first = false;
        console.log(name + " " + screen_name);
        $("#" + screen_name).attr("style", "margin-left: 100px; margin-top: 5%; height: 150px; font-size: large; cursor: pointer; padding: 1%;");
        $("#" + screen_name).html(name + "<br /><br /><a href='userShow.php?screen_name=" + screen_name + "'><button class='btn btn-primary'>Get Details</button></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='makeFriend.php?screen_name=" + screen_name + "'><button class='btn btn-primary'>Make Friend</button></a>")
    }
};

也许解决方案是保留已经存在的控件的记录,然后只创建它们,如果它们还没有。