javascript - 如何通过 id on live 加载特定的 php 文件以显示在悬停 div 上

标签 javascript php jquery css

我制作了一个更新侧边栏,它在 10 秒间隔后加载新闻。

现在我想,当我将鼠标悬停在侧边栏的信号新闻上时,它会在侧边栏中显示完整的故事,而该侧边栏会从特定的 php 文件(例如 news.php?id=".$id."

我的悬停 div 运行良好并显示了一个 div,但我无法理解如何通过 id 在此处加载实时完整故事

再次清除;如何通过 id 实时加载特定的 php 文件以显示在悬停 div 上

我想做类似 facebook 右侧栏自动收报机的事情。在悬停特定帖子时显示完整故事。

我的 js

$(".upbox1").mouseover(function() {
  var pos = $(this).position();
  var width = $(this).outerWidth();
    $("#menu").css({
        position: "absolute",
        top: pos.top + "px",
        left: (pos.right + width) + "px"
    }).fadeIn("slow");
});
  $("#menu").mouseout(function() {
    $("#menu").fadeOut("slow");
  });
  $("body").click(function() {
    $("#menu").fadeOut("slow");
  });

下面是我的悬停 div。

echo'<div class="popup" id="menu">';
  // Full story will goes here from news.php?id=xxxxx
echo'</div>';

最佳答案

$(".upbox1").mouseover(function() {
    var id = $(this).attr("data-href"); //for example, put a data-href attr in your class with the id of the post
    $.get("php_file.php?id="+id, function(data) {
        //data is what php_file will return
        $(".menu").html(data); //this inserts into the class menu the data that the php file gave you
    });
});

在 php 文件中,对数据库使用查询并检索信息。并回显你想要的所有数据,例如:

$myData = "<div>".$data['title']."</div>";
$myData .= "<div>".$data['description']."</div>";
echo $myData;

关于javascript - 如何通过 id on live 加载特定的 php 文件以显示在悬停 div 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27488649/

相关文章:

javascript检查图像是否存在

javascript - 如何使用 Javascript 或 jQuery 表单编辑 .txt 文件

php - 使用关系检查其他表中的状态

php - CakePHP3 在 default.ctp 中获取用户

javascript - 段落中的新行不起作用

javascript - 未捕获( promise )错误 : The query requires an index

php - Doctrine 2 - 如何在关系中使用从缓存中检索的对象

jquery - 如果CKEditor中的内容发生改变

jquery - 如何捕捉 MobiScroll onClose 事件

javascript - 如何聚合onMouse和onTouch,使canvas可以在鼠标和ipad上使用?