开发者

Jquery disabling submit button

开发者 https://www.devze.com 2023-04-08 04:53 出处:网络
I have a form with a text box and a submit button. I disable the submit button once it is clicked for 5 seconds. If nothing is typed in the text field and the user tries submitting, the button is disa

I have a form with a text box and a submit button. I disable the submit button once it is clicked for 5 seconds. If nothing is typed in the text field and the user tries submitting, the button is disabled for 1 second and nothing is posted.

The problem I am having is that on a friends Mac in Chrome and Firefox, when the button is disabled, the button disappears and a grey box is left until the 5 seconds are up, but on my Windows computer with Chrome and Firefox the button is just faded out. Is there a reason why this is happening? He said that it was working fine and then it suddenly started happening.

Here is my HTML:

<form style="position:relative; top:-5px;" action="" method="post">
    <strong>Message:</strong>
    <input type="text" id="message" name="message" class="message">
    <input type="submit" id="submit" value="Submit"/>
</form>

And JavaScript:

<script type="text/javascript">

$(function() {
    refresh_shoutbox();

    setInterval("refresh_shoutbox()", 15000);

    var running = false;

    $("#message").keypress(function(e) { 
        if(e.which == 13 && running === true) { 
            return false; 
        } 
    }); 

    $("#submit").click(function(event) {
        if(this.disabled) {
            event.preventDefault();
        }   

        if($("#message").val() != '') {
            running = true;

            $("#submit").attr("disabled","disabled");

            setTimeout(function() {
                $("#submit").removeAttr("disabled")
                running = false;
            }, 5000);
        } else {
            $("#开发者_开发技巧submit").attr("disabled", "disabled");
                setTimeout(function() {
                    $("#submit").removeAttr("disabled")
                    running = false;
                }, 1000);

            return false;
        }

// Ajax calls and the rest of the script


I think there's a bug in the latest webkit. I have buttons that were rendering ok until a week ago showing a weird grey rectangle now as well

You should use the html inspector and check that the button tag has

disabled="disabled"

as an attribute

0

精彩评论

暂无评论...
验证码 换一张
取 消