1

我喜欢在提交按钮上设置延迟。换句话说,单击该按钮后会变灰几秒钟。我怎样才能用js完成这个?

4

4 回答 4

4

这可能会对您有所帮助:http: //jsfiddle.net/jhNcM/

<input type="button" id="aaa" value="button" />

$('#aaa').click(function() {
    var aaa =  $(this);
    aaa.prop('disabled', true);
    setTimeout(function() {
        aaa.prop('disabled', false);
    }, 3000);
});
于 2012-11-13T13:30:55.753 回答
2

纯 JavaScript:http: //jsfiddle.net/R5p5q/1/

<form id="myForm">
    <input id="mySubmit" type="submit" value="GO" />
</form>

​</p>

var myForm = document.getElementById('myForm');

myForm.addEventListener("submit", function(evt) {
    var elemSubmit = document.getElementById('mySubmit');
    elemSubmit.setAttribute("disabled", "disabled");

    // Removes disabling after 3 seconds
    window.setTimeout(function() {
        elemSubmit.removeAttribute("disabled");
    }, 3e3);
},false);
于 2012-11-13T13:35:04.437 回答
1

有一种方法可以做到这一点http://jsfiddle.net/Ktk6f/

HTML

<input type="submit" value="submitData" id="myButton" />

JS

$('#myButton').click(function(){
    var that = $(this);
    that.attr('disabled', true);
    var timer = setTimeout(function(){
        that.attr('disabled', false);
    }, 1000);
});

它需要 jQuery JS 框架

于 2012-11-13T13:27:59.617 回答
0
$("#button").click(function() {
    if (this.disabled) {
        return;
    }
    this.disabled = true;
    setTimeout($.proxy(function() {
        this.disabled = false;
    }, this), 3000);
});
于 2012-11-13T13:27:43.987 回答