我有两个文件..一个.jspx和其他.js页面。 .jspx文件的代码:
<form name="vacNotificationEdit" method="post" >
<input type="button" class="button_medium" name="Save As Draft" id="Save" value="Save As Draft" onclick="javascript:vacFunction('save');" ><![CDATA[ ]]></input>
<input type="submit" class="button_big" name="Submit for Review" id="Submit" value="Submit for Review" onclick="javascript:vacFunction('submit');" ></input>
</form>
.js页面的代码:
function vacFunction(strAction)
{
if(deptMgrId!=""){
document.vacNotificationEdit.hidAction.value = strAction;
document.vacNotificationEdit.action ="vacationNotification";
document.vacNotificationEdit.submit();
}
}
我需要在点击一次后禁用提交按钮。请帮我解决这个问题。我卡住了。我使用了disabled = true / false但没有运气。
答案 0 :(得分:0)
您应首先提交表单,然后更改提交的值:
以下是工作示例:https://output.jsbin.com/mobogoguxe
https://jsbin.com/mobogoguxe/edit?html
使用表单提交禁用submit
按钮:
onClick="this.form.submit(); this.disabled=true; this.value='Sending…'; "
仅禁用submit
按钮:
onClick="this.disabled=true; this.value='Sending…'; "
在这里演示:https://jsbin.com/xakata/8/edit?html,output
<!DOCTYPE HTML>
<html lang="ar">
<head>
<meta charset=utf8>
<script type="text/javascript">
function vacFunction(btnAction)
{
if(btnAction.id == 'Submit'){
//if clicked on 'Submit for Review' button
btnAction.disabled = true;
console.log("Submit for Review");
}
if(btnAction.id == 'Save'){
//if clicked on 'Save As Draft' button
btnAction.disabled = true;
console.log("Save As Draft");
}
return false;
}
</script>
</head>
<body>
<form name="vacNotificationEdit" method="post" >
<input type="button" class="button_medium" name="Save As Draft" id="Save" value="Save As Draft" onClick="return vacFunction(this);" ><![CDATA[ ]]></input>
<input type="submit" class="button_big" name="Submit for Review" id="Submit" value="Submit for Review" onClick="return vacFunction(this);"></input>
</form>
</body>
</html>