简体   繁体   English

如何在AJAX加载的标签中初始化jquery函数?

[英]How do I initialize a jquery function in an AJAX loaded tab?

I have my AJAX loaded tabs working correctly and this is the code: 我的AJAX加载选项卡工作正常,这是代码:

<div id="tabs">
  <ul>
    <li><a href="../about-leadership-admin-ajax/">Leadership / Admin</a></li>
    <li><a href="../about-sales-marketing-ajax/">Sales & Marketing</a></li>
    <li><a href="../about-service-desk-technicians-ajax/">Service Desk Technicians</a></li>
    <li><a href="../about-technology-consultants-ajax/">Technology Consultants</a></li>
    <li><a href="../about-manufacturing-consultants-ajax/">Manufacturing Consultants</a></li>
    <li><a href="../about-salesforce-cpm-consultants-ajax/">Salesforce/CPM Consultants</a></li>
    <li><a href="../about-developers-ajax/">Developers</a></li>
  </ul>
</div>

and my initilization script: 和我的初始化脚本:

<script>
  jQuery(function() {
    jQuery( "#tabs" ).tabs().addClass( "ui-tabs-vertical ui-helper-clearfix" );
    jQuery( "#tabs li" ).removeClass( "ui-corner-top" ).addClass( "ui-corner-left" );

    jQuery( "#tabs" ).tabs({
      beforeLoad: function( event, ui ) {
        ui.jqXHR.error(function() {
          ui.panel.html(
            "Couldn't load this tab. We'll try to fix this as soon as possible." );
        });
      }
    });
  });
</script>

I have a jQuery slider on each one of the tabs. 我在每个选项卡上都有一个jQuery滑块。 Only the first one (in the first tab that is loaded) works correctly until I navigate to a new one. 只有第一个(在加载的第一个选项卡中)可以正常工作,直到我导航到一个新的。 When I come back to the first tab the slider is all screwed up. 当我回到第一个选项卡时,滑块已全部拧紧。 The initialization script I need to have on each AJAX loaded tab is: 我需要在每个AJAX加载选项卡上具有的初始化脚本是:

<script>
jQuery(document).ready(function(){
jQuery('#horiz_container_outer').horizontalScroll();
});
</script>

I know (document).ready does not work. 我知道(document).ready无法正常工作。 I need to know where and what to place in my tabs initialization script to make this work. 我需要知道在选项卡初始化脚本中的位置以及放置位置,才能完成此工作。

I know I need to use one of several functions in jQuery but I have no idea what to use and where. 我知道我需要使用jQuery中的几个功能之一,但我不知道该在哪里使用什么。 My options look like .load(), .bind(), .success(). 我的选项看起来像.load()、. bind()、. success()。

I would love it if someone could point me in the right direction and be specific. 如果有人可以指出我正确的方向并做到具体,我会喜欢的。 Thanks in advance. 提前致谢。 I am also willing to pay for a solution:) 我也愿意为解决方案付费:)

Try using the activate event 尝试使用Activate事件

jQuery( "#tabs" ).tabs({
  beforeLoad: function( event, ui ) {
    ui.jqXHR.error(function() {
      ui.panel.html(
        "Couldn't load this tab. We'll try to fix this as soon as possible." );
    });
  }
  activate: function( event, ui ) {
    jQuery('#horiz_container_outer').horizontalScroll();
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM