python - 使用 .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>
解决方案
使用submit
表单上的事件:
$("#pb").submit(function() {
$(this).find(":submit").replaceWith( "<div class=\"spinner-border\" role=\"status\"><span class=\"sr-only\">Loading...</span></div>");
});
推荐阅读
- python - 使用于访问 Google 云存储的 Google python 客户端库命中存根 API
- bash - 在 bash 中,有没有办法在整数列表中搜索连续序列并删除这些序列中除了最后一个数字之外的所有数字?
- r - 使用 diagrammeR,如何根据条件制作节点填充颜色?
- python-3.x - 如何将3d数组转换为字符串
- python - 如何在此代码中用空格替换标点符号?
- python - 如何过滤模型中的外键?
- hibernate - grails 3.3:带有 findOrSaveWhere 的 org.hibernate.TransientObjectException
- html - 需要帮助将 div 放在一起并将最后一个放在底部
- php - Symfony 表单不提交数据 - POST 请求为空
- wordpress - 在 .htaccess 中为 WordPress 安全添加安全标头