表单现在以第二种形式加载第一种形式的错误

时间:2012-05-10 02:41:23

标签: jquery django forms append clone

从我改变了我的代码后出于某种原因:

<script type="text/javascript">
$(document).ready(function(){

    $("recipebutton1").click(function(){
        $('#create_form_span').css('display', 'none');
        $("#recipe_display").replaceWith($('recipepopup1').css('display','block'));
    });
    $("#recipebutton2").click(function(){
        $('#create_form_span').css('display', 'none');
        $("#recipe_display").replaceWith($('#recipepopup2').css('display','block'));
    });
    $("#recipebutton3").click(function(){
        $('#create_form_span').css('display', 'none');
        $("#recipe_display").replaceWith($('#recipepopup3').css('display','block'));
    });
    $("#recipebutton4").click(function(){
        $('#create_form_span').css('display', 'none');
        $("#recipe_display").replaceWith($('#recipepopup4').css('display','block'));
    });
    $("#recipebutton5").click(function(){
        $('#create_form_span').css('display', 'none');
        $("#recipe_display").replaceWith($('#recipepopup5').css('display','block'));
    });
    $("#recipebutton6").click(function(){
        $('#create_form_span').css('display', 'none');
        $("#recipe_display").replaceWith($('#recipepopup6').css('display','block'));
    });
    $(".create").click(function(){
        $('.recipepopup').css('display', 'none');
        $('#create_form_span').css('display', 'block');
        });
});
</script>   

到此:

<script type="text/javascript">
$(document).ready(function(){
    $("#recipebutton1").click(function(){
        $('#create_form_span').css('display', 'none');
        $(".recipepopup").css('display','none');
        $("#recipe_display").empty();
        $('#recipepopup1').clone().attr('id','clone1').css('display','block').appendTo('#recipe_display'); // append to where you want

    });
    $("#recipebutton2").click(function(){
        $('#create_form_span').css('display', 'none');
        $(".recipepopup").css('display','none');
        $("#recipe_display").empty();
        $('#recipepopup2').clone().attr('id','clone2').css('display','block').appendTo('#recipe_display'); // append to where you want
    });
    $("#recipebutton3").click(function(){
        $('#create_form_span').css('display', 'none');
        $(".recipepopup").css('display','none');
        $("#recipe_display").empty();
        $('#recipepopup3').clone().attr('id','clone3').css('display','block').appendTo('#recipe_display'); // append to where you want
    });
    $("#recipebutton4").click(function(){
        $('#create_form_span').css('display', 'none');
        $(".recipepopup").css('display','none');
        $("#recipe_display").empty();
        $('#recipepopup4').clone().attr('id','clone4').css('display','block').appendTo('#recipe_display'); // append to where you want
    });
    $("#recipebutton5").click(function(){
        $('#create_form_span').css('display', 'none');
        $("#recipe_display").empty();
        $('#recipepopup5').clone().attr('id','clone5').css('display','block').appendTo('#recipe_display'); // append to where you want
    });
    $("#recipebutton6").click(function(){
        $('#create_form_span').css('display', 'none');
        $(".recipepopup").css('display','none');
        $("#recipe_display").empty();
        $('#recipepopup6').clone().attr('id','clone6').css('display','block').appendTo('#recipe_display'); // append to where you want
    });
    $(".create").click(function(){
        $("#recipe_display").empty();
        $('#create_form_span').css('display', 'block');
        });
});
</script>   

已经成功了,所以我的表单现在只是在当前的

下不断加载一个新表单

任何人都可以想到为什么会发生这种事情的原因吗?它让我绝对疯了!

凯蒂

1 个答案:

答案 0 :(得分:0)

我不知道是什么导致表单连续加载到自身下面但我能够通过将html加载到div而不是appending / replaceWith来解决问题

这非常有效,我很高兴我现在知道如何使用jquerys .html功能