gpt4 book ai didi

javascript - 我的另一个网页的链接不起作用

转载 作者:行者123 更新时间:2023-11-28 07:01:10 25 4
gpt4 key购买 nike

我尝试使用 PHP 的 Twitter API 并创建了一个部分,用户可以在其中了解建议关注的人...

这是我的文件 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结果也是一样的。

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

最佳答案

这与当您将鼠标悬停在按钮上时函数 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>")
}
};

也许一个解决方案是记录已经存在的控件,然后仅在它们不存在时才创建它们。

关于javascript - 我的另一个网页的链接不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33222597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com