【问题标题】:Form now loads errors in a second form underneath the first表单现在在第一个表单下方以第二个表单加载错误
【发布时间】:2012-05-18 14:29:18
【问题描述】:

由于某种原因,我从这里更改了我的代码:

<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>   

已经做到了,所以我的表单现在只是不断地在当前表单下加载一个新表单

谁能想到为什么会发生这样的事情?它把我逼疯了!

凯蒂

【问题讨论】:

  • 似乎表单将表单附加到自身,所以很奇怪
  • 你会做一个小提琴吗?使用包含一些 HTML 的工作模型会更容易诊断此问题。
  • 我会尝试我从未做过,这是一个 django 项目
  • 嗯,我对 django 了解不多,但 jQuery 应该是一样的。看看你能用小提琴做什么,或者如果你有一个工作页面,那么也许我可以触发它并检查一下。
  • 我为这么糟糕的问题道歉 - 我最终解决了这个问题

标签: jquery django forms append clone


【解决方案1】:

我不知道是什么导致表单在自身下方不断加载,但我能够通过将 html 加载到 div 而不是追加/替换来解决问题

效果很好,我很高兴我现在知道如何使用 jquerys .html 功能

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-24
    • 1970-01-01
    • 2016-11-10
    • 1970-01-01
    相关资源
    最近更新 更多