javascript - 禁用提交按钮并显示消息

标签 javascript

我希望能够在提交表单时禁用提交按钮,也希望在提交表单时添加一条消息,例如(“这可能需要一段时间”)。

<form id="myform" method="post" action="default.asp" onsubmit="return Validate(this);"> 

<p>Select credit card:
    <select tabindex="11" id="CardType"> 
        <option value="AmEx">American Express</option> 
        <option value="CarteBlanche">Carte Blanche</option> 
    </select> 
</p>

<p>Enter number:
    <input type="text" id="CardNumber" maxlength="24" size="24" value="1234" />
    <input type="submit" id="submitbutton" /> 
</p> 

</form>

最佳答案

修改您的 Validate() 函数以包括禁用提交按钮并显示消息:

function Validate(f) {
    var isValid = true;
    // do validation stuff
    if (isValid) {
        f.submitbutton.disabled = true;
        document.getElementById("submitMessage").style.display = "block";
    }
    return isValid;
}

http://jsfiddle.net/gilly3/EjkSV/

关于javascript - 禁用提交按钮并显示消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5872176/

相关文章:

javascript - 如何以编程方式强制 Capacitor App 重新加载

javascript - greasemonkey - 将 onclick 事件添加到现有按钮

Javascript 小书签 : how to replace URL parts?

javascript - 使用 javascript 函数加载 View

javascript - 如何在html中建立不同select标签的option标签之间的关系

javascript - Google map - 模态窗口 (Wordpress ACF)

javascript - 在 AngularJS 中的已解决的 Promise 上使用 ng-model (奇怪的行为)

javascript - 如何验证Spring表单:form's form:password with JQuery Validation?

javascript - 为什么 $routeParams 不起作用?不明确的

javascript - 在 JavaScript 中仅使用 `.reduce()` 交换数组中的 2 个元素?