首页 > 解决方案 > 使用 .replacewith 时表单未提交

问题描述

嘿,我正在尝试创建一个表单,当提交时,使用 jquery 将按钮替换为加载轮,但是每当我用它运行它时,.submit("pb")它不会用微调器替换按钮,但是当我删除.submit("pb")它时,它不会提交表单,但它会替换带有微调器的按钮...如何使用微调器替换按钮并提交表单?

html代码

<form id="pb" method="POST" action="http://localhost:5000/simulator">
                        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
                        <script>
                            $(document).ready(function () {
                                $("button").submit("pb").click(function ()  {
                                    $("button:last").replaceWith( "<div class=\"spinner-border\" role=\"status\"><span class=\"sr-only\">Loading...</span></div>" );
                                });
                            });
                        </script>
                        <button type="submit" class="btn btn-success btn-ladda-progress" data-style="expand-right">
                            Submit
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </form>

标签: pythonjquerysqlflask

解决方案


使用submit表单上的事件:

$("#pb").submit(function() {
    $(this).find(":submit").replaceWith( "<div class=\"spinner-border\" role=\"status\"><span class=\"sr-only\">Loading...</span></div>");
});

推荐阅读