Jquery 然后加载内容。在没有ajax请求的情况下切换内容
我有一个钮扣。当我点击它时,内容就会加载。当我在内容切换后单击它时(显示:无)。但它仍然发送ajax请求 如何检查内容是否已加载,以便在没有ajax请求的情况下开始切换Jquery 然后加载内容。在没有ajax请求的情况下切换内容,jquery,ajax,Jquery,Ajax,我有一个钮扣。当我点击它时,内容就会加载。当我在内容切换后单击它时(显示:无)。但它仍然发送ajax请求 如何检查内容是否已加载,以便在没有ajax请求的情况下开始切换 <div id="morechan"> <a id="btnC" href="#" title="Kanalu saraksts"><i class="icon-caret-down"></i></a> </div> <div id="chan
<div id="morechan">
<a id="btnC" href="#" title="Kanalu saraksts"><i class="icon-caret-down"></i></a>
</div>
<div id="channel-list">
</div><!-- end channel-list -->
(function($) {
$("#btnC").click(function() {
$('#channel-list').html('loading...').load('channels.html');
});
})(jQuery);
(函数($){
$(“#btnC”)。单击(函数(){
$('#channel list').html('loading…').load('channels.html');
});
})(jQuery);
我建议设置数据属性并对其进行测试,如果未设置,则防止加载
$("#btnC").click(function() {
if( typeof( $('#channel-list').data("contentLoaded") ) != "undefined" ) {
//Do toggle code here.
return;
} else {
//Do load code here.
$('#channel-list').load("http://www.someurl.com",function() {
$(this).data("contentLoaded",true);
});
}
});
当/如果需要重新加载内容时,将contentLoaded
设置为false
,并检查单击事件中的true
或false
var contentLoaded = $('#channel-list').data("contentLoaded");
if( typeof( contentLoaded ) != "undefined" && contentLoaded ) {
//Do toggle code here.
return;
}
您可以在问题中包含代码吗?请编辑您的问题并添加jquery代码。