ada*_*dam 12 javascript jquery dom
我有一个功能,我目前正在使用它来显示隐藏的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); } }); });
好的,既然我已经解决了这个问题,我还有一个问题,
我有另一个函数,如果单击一个按钮,将删除插入的div.现在它没有工作,额外的div没有加载到页面加载的dom.我如何触发功能现在删除这些?
jQuery(function(){//隐藏答案
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);
});
Run Code Online (Sandbox Code Playgroud)
});
Pim*_*ger 10
如何在最后一个div之后添加它.
$('.a_type:last').insertAfter('<div class="a_type">content</div>');
Run Code Online (Sandbox Code Playgroud)
编辑
你可以通过对somefile.php的AJAX调用获取信息,然后somefile应该在div中返回你想要的内容:
$.get('path/to/somefile.php', function(data){
$('.a_type:last').insertAfter('<div class="a_type">' + data + '</div>');
});
Run Code Online (Sandbox Code Playgroud)
Somefile.php应该是这样的:
<?php
session_start();
$sessiondata = $_SESSION['data'];
echo "Whatever you type here will come inside the div bla bla $sessiondata";
?>
Run Code Online (Sandbox Code Playgroud)
编辑
好的,试试这个:
jQuery(function(){ // Add Answer jQuery(".add_answer").click(function(){ if(count >= "4"){ alert('Only 4 Answers Allowed'); }else{ var count = $(this).attr("alt"); count++; $('.a_type_'+count-1+'').insertAfter(' Place content back here'); $(this).attr("alt", count); } }); });
如果你仍然需要,只需混合使用AJAX即可.
归档时间: |
|
查看次数: |
36872 次 |
最近记录: |