我有一个正在使用的仿函数来显示隐藏的div.a_type

我如何修改此代码,以便与其在隐藏的div中淡入淡出,
我可以将新的div添加到DOM

jQuery(function(){   // Add Answer

    jQuery(".add_answer").click(function(){
      if(count >= "4"){
        alert('Only 4 Answers Allowed');
        }else{
      var count = $(this).attr("alt");
      count++;
      $(this).parents('div:first').find('.a_type_'+count+'').fadeIn();
      $(this).attr("alt", count);
    }

    });

});

Ok, now that i have this sorted out, i have one more question,

I have another function that removes the inserted div's if a button is clicked.It's not working now that the additional divs are not loaded into the dom on pageload.How can i trigger the function to remove these now?

jQuery(function(){ // Hide Answer

jQuery(".destroy_answer").click(function(){
  $(this).parents("div:first").fadeOut(function (){ $(this).remove() });
   var count = $(this).parents('div:first').parents('div:first').find('.add_answer').attr("alt");
   count--;
   $(this).parents('div:first').parents('div:first').find('.add_answer').attr("alt", count);

});

});

最佳答案

如何在最后一个div之后添加它。

$('.a_type:last').insertAfter('<div class="a_type">content</div>');

编辑
您可以通过AJAX调用somefile.php来获取信息,然后somefile应该在div中返回您想要的内容:
$.get('path/to/somefile.php', function(data){
 $('.a_type:last').insertAfter('<div class="a_type">' + data + '</div>');
});

Somefile.php应该是这样的:
<?php
 session_start();
 $sessiondata = $_SESSION['data'];
 echo "Whatever you type here will come inside the div bla bla $sessiondata";
?>

编辑
好的,试试这个:

jQuery(function(){//添加答案

jQuery(“。add_answer”)。click(function(){
if(count> =“4”){
alert('仅允许4个答案');
}别的{
var count = $(this).attr(“alt”);
数++;
$('。a_type _'+ count-1 +'')。insertAfter('
将内容放回这里');
$(this).attr(“alt”,count);
}

});

});

如果您仍然需要,只需混入AJAX。

10-05 20:40
查看更多