2013-02-26 68 views
0

我不知道是否问题是与jquery的加载函数或与jquery的选项卡(或没有他们),但我的问题是,当切换tab2到tab1(见下面的代码)标签的内容是清除并再次加载,导致闪烁。数据通过加载函数动态加载到tab1(id:the_paragraph)中的段落元素。从tab1切换到tab2时不会发生此问题。Jquery转换标签时闪烁

若要重现: 请转至http://mumka12345.appspot.com/,将鼠标悬停在tab2上,然后返回到tab1。我已经放置了两条警报来强调这个问题。

这是一个有2个选项卡

<!DOCTYPE html> 
<html> 
<head> 

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> 
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script> 
<script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js'></script> 


<script> 
    $(document).ready(function() 
    { 
     $("#tabs").tabs({ 
     load: function(event, ui) 
     { 
      $(ui.panel).delegate('a', 'click', function(event) 
      { 
       $(ui.panel).load(this.href); 
       event.preventDefault(); 
      }); 
     }, 
     event: "mouseover" 
     }); 
    }); 
</script> 

</head> 

<body style="font-size:62.5%;"> 

<div id="tabs"> 
    <ul> 
     <li><a href="/tab1"><span>tab1</span></a></li> 
     <li><a href="/tab2"><span>tab2</span></a></li>   
    </ul> 
</div> 
</body> 
</html> 

服务器返回请求“TAB1”时,以下我的主页:

<!DOCTYPE html> 
<html> 
<head> 
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script> 
<script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js'></script> 


<script> 
    $(function() 
    { 
     alert('ready'); 
     $("#the_paragraph").load("/fillParagraph" , function() 
     { 
      alert('paragraph loaded'); 

     }); 
    }); 
</script> 

</head>' 


<body">  
<div id="container"> 
<p id="the_paragraph"> 
</p>  

</body> 
</html> 

服务器返回的字符串“你好TAB2”当客户端当客户端请求'fillParagraph'时,服务器返回字符串'Dynamic Fill'

回答

0

对于标签1的响应触发了relo jQuery和JQuery UI的广告肯定没有帮助。

从响应中删除这些脚本引用。

&尝试使用console.log而不是alert。

+0

感谢您的快速响应,但警报与它无关。 – 2013-02-26 19:30:32

+0

警报提示只是为了让您的工作流程更容易一些。我的答案是关于重新加载jQuery和jQuery UI。 此外,在您的回复中返回的页面还有另一个调用来重新加载您所需的内容。为什么不只是第一次返回内容? – Mattyod 2013-02-26 19:33:25