0

我已经设法将新页面加载到div(感谢大家的帮助),但它看起来很糟糕(有菜单栏和徽标,但我只想要内容),所以我只需要div从新页面加载. 我尝试了一个新脚本,但被重定向到新页面。请帮忙。

<script>
   jQuery(document).ready(function() {
           jQuery('.stil_link_img a').click(function(){
             var x = $(this).attr("href") + "#content_eco";
             jQuery("#new_page").load(x);
             return false;
           });
   });   


</script>
<div id="pachete">
   <?php 
      $result=mysql_query("SELECT* FROM imagini"); 
      while($data=mysql_fetch_row($result)){
                  if( ($data[3]==1)&&($data[2]==2) ){ ?>
   <div class="stil_link_img">
      <a href="<?php echo $data[4];?>" class="poza_efect"><img  src="upload/<?php echo $data[1];?>"></a> 
   </div>
   <?php               }
      }?>
</div>
<div id="new_page">
   //some content which should be replaced with my loaded page
</div>
4

1 回答 1

1
jQuery(document).ready(function() {
    jQuery('.stil_link_img a').click(function(){
      var $pageContent = jQuery('<div/>').load($(this).attr("href"));
      jQuery("#new_page").html(jQuery("#content_eco",$pageContent).html());
      return false;
    });
});  

我假设#content_eco 是新页面中的部门ID(来自href 属性的url)。

或者您可以仅从 url 加载内容并避免链接回发为

<script>
   jQuery(document).ready(function() {
           jQuery('.stil_link_img a').click(function(){
             var x = $(this).attr("rel") + " #content_eco";
             jQuery("#new_page").load(x);
             return false;
           });
   });
</script>
<div id="pachete">
   <?php 
      $result=mysql_query("SELECT* FROM imagini"); 
      while($data=mysql_fetch_row($result)){
                  if( ($data[3]==1)&&($data[2]==2) ){ ?>
   <div class="stil_link_img">
      <a href='#' rel="<?php echo $data[4];?>" class="poza_efect"><img  src="upload/<?php echo $data[1];?>"></a> 
   </div>
   <?php               }
      }?>
</div>
<div id="new_page">
   //some content which should be replaced with my loaded page
</div>

希望这对您有所帮助。

于 2013-02-14T09:26:15.973 回答