Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui UI选项卡加载外部页面,jQuery不再工作_Jquery Ui_Jquery Ui Tabs_Dynamic Loading - Fatal编程技术网

Jquery ui UI选项卡加载外部页面,jQuery不再工作

Jquery ui UI选项卡加载外部页面,jQuery不再工作,jquery-ui,jquery-ui-tabs,dynamic-loading,Jquery Ui,Jquery Ui Tabs,Dynamic Loading,当我使用UI选项卡并将外部页面加载到tabcontent-DIV中时,我遇到了一个问题。当该页面加载后,该页面的所有jquery似乎不再工作。我读了一些关于回调的文章,但一点也不清楚 <script type="text/javascript"> jQuery(document).ready(function() { // define tabs $('#tabs').tabs(); // after loadin

当我使用UI选项卡并将外部页面加载到tabcontent-DIV中时,我遇到了一个问题。当该页面加载后,该页面的所有jquery似乎不再工作。我读了一些关于回调的文章,但一点也不清楚

    <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>
示例:我通过ui选项卡加载一个外部页面,加载的内容包括一个DIV,该DIV应在index.html中自动隐藏为jqueryd 添加jQuery click事件只是为了显示实时事件正在工作。 但我无法让自动隐藏工作后,加载内容

    <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>
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>

jQuery(文档).ready(函数(){
//定义选项卡
$(“#tabs”).tabs();
//加载外部页面后,div“autohideafterload”将自动隐藏。
$('#autohideafterload')。隐藏('slow');
$('#autohideafterload').live('click',function(){
$('#autohideafterload')。隐藏('slow');
});
});
loadcontent.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>
<div id="autohideafterload">This div will hide automatically after loaded this external page.</div>
加载此外部页面后,此div将自动隐藏。

我缺少什么?

在触发选项卡的加载事件后绑定事件

    <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>
$('#tabs')
    .bind('tabsload', function(event, ui) {
        $('#autohideafterload').hide('slow'); 
    })
    .tabs();

您正在尝试绑定到(尚未)存在的元素。您需要在项目加载后进行绑定,而监听事件是最好的方法。

好的,但是当我有很多元素要为这个外部加载的页面绑定时,我是否应该以这种方式绑定所有分开的元素?我认为这是一个很大的工作。没有别的办法吗?
    <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>