Jquery UI button gets disabled on refresh

后端 未结 5 621
醉酒成梦
醉酒成梦 2021-02-08 10:16

I asked about this on the jquery forum a few weeks ago without luck, so I will try again here :)

I\'ve made a simple widget for a project I\'m working on, but I have enc

5条回答
  •  萌比男神i
    2021-02-08 11:00

    Here is the solution I found works really well in all browsers...

    I give each button (that can be disabled) a class 'js_submit'

    I then re-enable any disabled buttons with class 'js_submit' on the pagehide event that fires when a page is unloaded.

    I wrap the event assignment inside a try catch to prevent browsers that don't support this event from throwing an error (such as IE).

    Here is the code:

    
    
    
    // Fix for firefox bfcache:
    try {
        window.addEventListener('pagehide', PageHideHandler, false);
    } catch (e) { }
    
    //Fires when a page is unloaded:
    function PageHideHandler() {
        //re-enable disabled submit buttons:
        $('.js_submit').attr('disabled', false);
    }
    

提交回复
热议问题