2010-01-26 98 views
0

我使用UI Tabs并将外部页面加载到tabcontent-DIV时遇到问题。加载页面后,此页面的所有jQueries似乎都不再起作用。我读了一些关于回调的内容,但一点都不清楚。UI Tab加载外部页面,jQueries不再工作

例如:我通过ui-tabs加载一个外部页面,加载的内容包含一个DIV,它应该会自动隐藏在index.html中的jQueried中 jQuery单击事件仅用于显示实时事件工作中。 但我无法得到自动隐藏工作,加载后的内容。

的index.html

<script type="text/javascript"> 

    jQuery(document).ready(function() { 

     // define tabs 
     $('#tabs').tabs(); 

     // after loading external page, the div "autohideafterload" will automatically hide. 
     $('#autohideafterload').hide('slow'); 

     $('#autohideafterload').live('click', function() { 
      $('#autohideafterload').hide('slow'); 
     }); 

    }); 

    </script> 

</head> 


<body> 

    <div id="tabs"> 
     <ul> 
      <li><a href="loadcontent.html" title="tabcontent"><span>Load data</span></a></li> 
     </ul> 
    </div> 

    <div id="tabcontent"></div> 

</body> 
</html> 

loadcontent.html

<div id="autohideafterload">This div will hide automatically after loaded this external page.</div> 

我在想什么?

回答

1

绑定你的事件被触发标签的load事件之后...

$('#tabs') 
    .bind('tabsload', function(event, ui) { 
     $('#autohideafterload').hide('slow'); 
    }) 
    .tabs(); 

你试图绑定到不(还)存在的元素。您需要在项目加载后进行绑定,并且收听该事件是执行此操作的最佳方式。

+0

好的,但是当我有很多要绑定这个外部加载页面的元素时,我应该用这种方式绑定这些元素吗?我认为这是很多工作。没有其他办法吗? – 2010-01-26 23:28:57