Detect if an element is visible (without using jQuery)

前端 未结 5 731
执笔经年
执笔经年 2021-02-07 11:20

I\'m trying to detect if an html element I gave an id is visible or not without using jquery.

The context:

In the forgotten user password page,

5条回答
  •  名媛妹妹
    2021-02-07 11:45

    As I was thinking about disabling the button, I'm here to write that I was wrong about my idea of solution for this problem, because it would be really costly to make it works. This way, after studying, testing some ideas and reading the ideas @gdoron and @AmeyaRote brought, I figured out that a simple solution was to hide the 'submit' button after clicking on it (the page is refreshed, the validation is checked and the button is available again after this process). So, here is the solution to solve the problem to avoid the user of clicking more than once on the submit button, for this particular case where I cannot disable it (if I disable after clicking, the form was not being submited):

    The HTML

    I just added the onclick attribute calling a javascript function I created to hide the button:

    
    

    The Javascript

    function avoidDoubleSubmit() {
        
            event_addEvent(window,'load',function(){document.ResetPasswordForm.secretAns.focus();});
            document.getElementById('general_Submit.Label').style.display ='none';
        
    }
    

提交回复
热议问题