javascript - 页面刷新后按钮应保持禁用状态

标签 javascript php jquery html css

我在提交按钮上应用了一段时间的残疾......一段时间后它被启用......即15 秒后....bt 如果我正在刷新页面然后按钮被启用...按钮失去了可用时间并被启用...请帮助我..

$(window).load(function(){
var enableSubmit = function(ele) {
    $(ele).removeAttr("disabled");
}

$("#submit").click(function() {
    var that = this;
    $(this).attr("disabled", true);
    setTimeout(function() { enableSubmit(that) }, 15000);
});
}); 


    var count = 1;
    function setColor(btn, color) {
        var property = document.getElementById(btn);
        if (count == 0) {
            property.style.backgroundColor = "#FFFFFF"
            count = 1;        
        }
        else {
            property.style.backgroundColor = "#7FFF00"
            count = 0;
        }
    }
<style type="text/css">
input[disabled] {
	background-color:#FF6347;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" id="submit" value="submit" class="btn" />

最佳答案

您可以做的是使用浏览器本地存储(HTML5 功能)在其中存储按钮状态,并在页面加载时从本地存储中获取该状态并使用 JS 将其分配给按钮。 对于使用 localstorage ,您可以在此链接上获得帮助: http://www.w3schools.com/html/html5_webstorage.asp .

在你的提交函数中:

$("#submit").click(function() {
    var that = this;
    $(this).attr("disabled", true);
    localStorage.setItem("button-state", 'true');
    setTimeout(function() {     $("#submit").attr('disabled',true);}, 15000);
});

在代码开头的 Window 内部加载:

$(window).load(function(){
  var buttonState=Boolean(localStorage.getItem("lastname"));
   $("#submit").attr('disabled',buttonState);
});

关于javascript - 页面刷新后按钮应保持禁用状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39290027/

相关文章:

javascript - 在 Javascript 中传递 PHP 变量

javascript - 在 Razor 中,接受不带小数的整数

php - 从 bash 运行一个 PHP 文件的多个实例并将结果附加到文件?

php - 在PHP作业方面需要帮助- friend 匹配算法

javascript - 如何在 SweetAlert2 中将 Datepicker 置于最前面?

php - 发布表单后重置隐藏变量

php - 在 php 中使用 xampp 发送邮件

javascript - 复制到剪贴板时如何避免移动浏览器中的页面滚动

javascript - 翻译后将 html 元素返回到其原始位置

javascript - $.getJSON执行问题: json to array is populated but not used