我有这样一个表格:
<form action="lol.php" method="POST">
<input type="text" name="fe" />
<input type="submit" id="submitbtn" value="submit" onclick="this.disabled = true;" />
</form>
在 Firefox 中它工作得很好,但在 Internet Explorer(最新版本)中按钮被禁用但表单不提交。我也试过:
<form action="lol.php" method="POST" onsubmit="document.getElementById('submitbtn').disabled = true">
并从提交按钮中删除了 onclick 代码,但效果相同。我应该使用什么代码才能在所有浏览器上运行?
最佳答案
好的,好的 hack 是准备第二个什么都不做的假按钮:
<form action="lol.php" method="POST">
<input type="text" name="fe" />
<input type="button" id="submitbtnDisabled" disabled="disabled" value="submit" style="display:none;" />
<input type="submit" id="submitbtn" value="submit" onclick="this.style.display='none'; document.getElementById('submitbtnDisabled').style.display='inline';" />
</form>
注意:
因为您说您没有使用 jQuery,所以我使用的是标准 JavaScript。唯一的建议是使用非侵入式 JavaScript 并将内联 CSS 移至样式表,以将脚本和样式与 HTML 分开。
关于javascript - 禁用提交按钮取消表单提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3393245/