2014-01-23 23 views
-1

我有a.php文件其中是一個div中的內容是要顯示使用Jquery這是行不通的。它不顯示jQuery的內容 一個div以及他們的jQuery中的annchor標籤onhooking它的內容div是一個iframe(在b.php)與divs內容使用ajax這應該工作,但我不知道是難道不是工作。無論是a.php只會和b.php是在同一文件夾jquery懸停與阿賈克斯不工作

無論在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> 

任何人都可以讓我知道我是錯的還是有更好的方法來實現它?

+0

你包含jQuery嗎? – Albzi

+0

雅使用...已更新代碼 – hir

+0

你爲什麼包括jQuery兩次?這導致問題 – szpic

回答

0

變化:

<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應該開始工作

+0

我做到了,但阿賈克斯不工作iframe劑量出現 – hir

0

這是一個艱苦的工作找出爲什麼懸停不工作。

根據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片段,然後將此ajax響應插入文件a.php中的div。使用iframes主要在麻煩。

+0

我試着讓你知道。謝謝你的解釋 – hir