Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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 然后加载内容。在没有ajax请求的情况下切换内容_Jquery_Ajax - Fatal编程技术网

Jquery 然后加载内容。在没有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

我有一个钮扣。当我点击它时,内容就会加载。当我在内容切换后单击它时(显示:无)。但它仍然发送ajax请求

如何检查内容是否已加载,以便在没有ajax请求的情况下开始切换

<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代码。