Jquery ui slideToggle和jQuery Ajax-新元素不可操作

Jquery ui slideToggle和jQuery Ajax-新元素不可操作,jquery-ui,jquery,Jquery Ui,Jquery,当我将新元素引入我的slideToggle时,它们看起来很好并且处于活动状态(默认情况下展开),但是如果我单击一个预先存在的元素,所有元素都会折叠,并且我无法展开新的ajax元素。基本上,新的ajax元素不是slideToggle组的一部分,因为它是在引入元素之前构建的。如何动态重建切换,或使新元素按预期运行 **jQUERY $('div.menu_body:eq(0)').show(); $('.acc .head:eq(0)').show().css({color:"#2B6893"});

当我将新元素引入我的slideToggle时,它们看起来很好并且处于活动状态(默认情况下展开),但是如果我单击一个预先存在的元素,所有元素都会折叠,并且我无法展开新的ajax元素。基本上,新的ajax元素不是slideToggle组的一部分,因为它是在引入元素之前构建的。如何动态重建切换,或使新元素按预期运行

**jQUERY

$('div.menu_body:eq(0)').show();
$('.acc .head:eq(0)').show().css({color:"#2B6893"});

$(".acc .head").click(function() {  
    $(this).css({color:"#2B6893"}).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
    $(this).siblings().css({color:"#404040"});
});
**阿贾克斯

<script type="text/javascript">
jQuery(document).ready(function() {
    setInterval("showNewFeeds()", 10000);
});
showNewFeeds() {
    $.ajax({
     type: 'POST',
     url: 'feed.php',
     data : {uid : '145', mid: '22', nid: 56'},
     success: function(response) {
       $('#feedNote').html(response).fadeIn('slow');
     },
     error: function (xhr, ajaxOptions, thrownError) {
       //alert(xhr.status);
       //alert(thrownError);
     }
   });
}
</script>";

jQuery(文档).ready(函数(){
setInterval(“showNewFeeds()”,10000);
});
showNewFeeds(){
$.ajax({
键入:“POST”,
url:'feed.php',
数据:{uid:'145',mid:'22',nid:56'},
成功:功能(响应){
$('#feedNote').html(response.fadeIn('slow');
},
错误:函数(xhr、ajaxOptions、thrownError){
//警报(xhr.状态);
//警报(thrownError);
}
});
}
";
**HTML

<div class="widget acc" id="feedNote">
  <div class="head"><h5>Header 1</h5></div>
  <div class="menu_body">
    <div>HTML 1</div>
  </div>
  <div class="head"><h5>Header 2</h5></div>
  <div class="menu_body">
    <div>HTML 2</div>
  </div>
</div>

标题1
HTML 1
标题2
HTML 2
试试:

$(document).on('click', '.acc .head', function() {  
  $(this).css({color:"#2B6893"}).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
  $(this).siblings().css({color:"#404040"});
});

而不是
。单击(function(){…})

,这样做了!还必须将HTML的插入更改为使用prepend,因为我的现有元素正在消失。$('#feedNote').prepend($(response).hide().fadeIn('slow'));好的,我认为您需要覆盖它们..无论如何,这是将事件附加到动态创建的元素的方法之一..很乐意为您提供帮助...)