0

我最近了解了 Jquery 弹出 div。
我使用了这个链接。我想要那种弹出式div。

但问题是,我需要多个弹出 div。
假设我在数据库表中有 15 个用户,那么我想要 15 个不同的链接。此外,每个弹出 div 都应该显示该用户的数据库信息。

我也找到了这个,但是这个弹出的 div 不会随着鼠标指针移动,并且当 div 宽度大于链接宽度时,这不起作用。

所以我想像第一个例子一样弹出 div。
我怎样才能做到这一点 ?

4

1 回答 1

0

我对这个问题的看法和你不同。所以这是我的想法。

1st-您不需要多个 div,因为使用 jquery 和 php 您可以根据需要操作单个 div。第二-说你展示你的 15 个人第一使工作更容易。假设您将它们存储到一些链接中,例如下一个示例,我们假设我们有一个 ID、一个名称、一个年龄和一个位置:

<?php
$sql = "SELECT * FROM persons";
$result = mysql_query($sql);
while(mysql_fetch_array($result)) {
echo '<a hred="#" class="trigger" id=' . $result['id'] . '>' . $result['name'] . '</a><br />';
}

现在使用 AJAX 我们显示悬停任何链接的结果:

$('a').mouseenter(function(e) {
var myperson = $(e.target).text();
$.ajax({
url: "details.php?current=" + myperson,
success: function(html){
if(html) {
$("a").append(html);  //here you'll have to get the current hovered link- this will dispaly the info on all the links on hovering one of them
}
}
}

现在在 details.php 页面中,我们将对当前人员进行查询:

<?php
$currpers = "SELECT * FROM persons WHERE name = '" . addslashes($_GET['current']) . "'") or die(mysql_error());
$results = mysql_query($currpers);
if(mysql_fetch_array($results )) {
echo '<div class="pop-up">
      <p>
      <strong>Age:</strong>' . $results ['age'] . '<br />
      <strong>Location:</strong> ' . $results ['location'] . '
      </p>
      </div>';
}
?>

注意:我没有对此进行测试。可能会有一些调整,但想法是一样的。

于 2013-07-29T11:54:50.630 回答