禁用提交按钮取消表单提交

fit*_*itz 3 html javascript forms internet-explorer

我有一个这样的表格:

<form action="lol.php" method="POST">
<input type="text" name="fe" />
<input type="submit" id="submitbtn" value="submit" onclick="this.disabled = true;" />
</form>
Run Code Online (Sandbox Code Playgroud)

并且在Firefox中它可以很好地工作,但在Internet Explorer(最新版本)中,该按钮被禁用但表单未提交.我也尝试过:

<form action="lol.php" method="POST" onsubmit="document.getElementById('submitbtn').disabled = true">
Run Code Online (Sandbox Code Playgroud)

并从提交按钮中删除了onclick代码,但效果相同.我应该使用什么代码才能在所有浏览器上运行?

roc*_*hal 5

好的,所以好的黑客是准备第二个什么都不做的假按钮:

<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>
Run Code Online (Sandbox Code Playgroud)

注意:

因为你说你没有使用jQuery我正在使用标准的JavaScript.唯一的建议是使用unbotrusive JavaScript并将内联CSS移动到样式表,只是为了将脚本和样式与HTML分开.