【问题标题】:jquery hover with ajax not workingjQuery悬停与ajax不起作用
【发布时间】:2014-03-08 14:56:58
【问题描述】:

我有一个 .php 文件,其中是正文中的一个 div,其内容将使用不工作的 Jquery 显示。它不显示 jquery 内容 一个 div 以及他们的 jquery 中的一个锚标签 onhovering 其内容 一个 div 是一个 iframe (在 b.php 中)与一个使用 ajax 的 divs 内容这应该可以工作,但我不确定它是否不工作。a.php 和b.php 在同一个文件夹中

在 a.php 和 b.php 中:

a.php:

$("document").ready(function()
{
    $("#pcontent").html('');
    $("#pcontent").append('<div class="product"><div class="title1"><div class="title">fdfsfsd</div><div class="title">&nbsp;&nbsp;<a class="reference">sdfsf</a></div><div id="showdata"></div></div></div>');
    $("#pcontent").fadeIn(1);

    $(".reference").hover(function()
    {
        $("#showdata").css("display","block");
        $.ajax({
            url:"b.php",
            type:"GET"
        });
    });
});

<div id="pcontent"></div>

b.php:

 $("document").ready(function()
 {
    $("#pcontent").html('');
    $("#pcontent").append('<div class="product"><div class="title1"><div class="title"><b>&nbsp;&nbsp;ghgj</b></div><div class="title">&nbsp;&nbsp;hjhk</div></div></div>');
    $("#pcontent").fadeIn(1);
});

 <iframe id="pcontent" width="100px" height="10px"></iframe>

谁能告诉我我错了还是有更好的方法来实现它?

【问题讨论】:

  • 你包含了 jQuery 吗?
  • 你正在使用...更新了代码
  • 你为什么要包含 jquery 两次?这会导致问题
  • 为什么要包含 jquery 1.3 和 jquery 1.8?
  • 对两个 szpic BeatAlex .... 已删除 jquery1.3 知道它显示了 a.php 的内容。但是 b.php 的 iframe 没有出现在显示数据 div 确实出现的悬停位置

标签: jquery iframe jquery-hover


【解决方案1】:

改变:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>

进入:

  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>   
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>

你的 ajax 应该开始工作了

【讨论】:

  • 我确实做到了,但 ajax 无法正常工作 iframe 出现
【解决方案2】:

很难弄清楚为什么悬停不起作用。

根据jquery的api文档,.hover()需要事件'onMouseOver()'的函数和'onMouseOut()'的函数。 第二件事是使用.css()。根据this post,该方法不适用于所有浏览器。为了调查,我使用了 Firefox。所以我使用 css 类对其进行了更改

这是我的工作示例,基于您的代码 (a.php):

<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>   
        <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
        <style>
            .displayObject {display:block;}
            .disDisplayObject {display:none;}
        </style>
        <script>
            $("document").ready(function()
            {
                $("#pcontent").html('');
                $("#pcontent").append('<div class="product"><div class="title1"><div class="title">fdfsfsd</div><div class="title">&nbsp;&nbsp;<a class="reference" style="text-decoration:underline">sdfsf</a></div><div id="showdata" class="disDisplayObject">showData</div></div></div>');
                $(".reference").hover(
                    function()
                    {
                        $("#showdata").fadeIn(300).removeClass("disDisplayObject").addClass("displayObject");
                    }, function() {
                        $("#showdata").fadeOut(300).removeClass("displayObject").addClass("disDisplayObject");
                    }
                );
            });
        </script>
    </head>
    <body>
        <div id="pcontent"></div>
    </body>
</html>

b.php的内容注释:

使用.html() 和.append() 对iframe 没有影响。我只能猜测你的意图是什么。我的理论是,您想将b.php 的内容插入a.php 的div 中。如果是这样,那么您可以采用更简单的方法:

开发b.php 以便生成适当的html sn-p,然后将此ajax 响应插入到文件a.php 中的div 中。使用 iframe 主要是遇到麻烦。

【讨论】:

  • 我试着让你知道。谢谢你的解释
猜你喜欢
  • 2012-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-28
  • 2013-01-06
  • 2013-05-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多