How to disable HTML links

后端 未结 14 1639
刺人心
刺人心 2020-11-22 13:00

I have a link button inside a which I have to disable. This works on IE but not working in Firefox and Chrome. Structure is - Link inside a <

14条回答
  •  野性不改
    2020-11-22 13:39

    There is one other possible way, and the one that I like best. Basically it's the same way lightbox disables a whole page, by placing a div and fiddling with z-index. Here is relevant snippets from a project of mine. This works in all browsers!!!!!

    Javascript (jQuery):

    var windowResizer = function(){
            var offset = $('#back').offset();   
            var buttontop = offset.top;
            var buttonleft = offset.left;
            $('#backdisabler').css({'top':buttontop,'left':buttonleft,'visibility':'visible'});
            offset = $('#next').offset();
            buttontop = offset.top;
            buttonleft = offset.left;
            $('#nextdisabler').css({'top':buttontop,'left':buttonleft,'visibility':'visible'});
    }
    
    $(document).ready(function() {
        $(window).resize(function() {   
            setTimeout(function() {
                windowResizer();
            }, 5); //when the maximize/restore buttons are pressed, we have to wait or it will fire to fast
        });
    });
    

    and in html

    
    
    
    
    

    So the resizer finds the anchor's (the images are just arrows) locations and places the disabler on top. The disabler's image is a translucent grey square (change the width/height of the disablers in the html to match your link) to show that it is disabled. The floating allows the page to resize dynamically, and the disablers will follow suit in windowResizer(). You can find suitable images through google. I have placed the relevant css inline for simplicity.

    then based on some condition,

    $('#backdisabler').css({'visibility':'hidden'});
    $('#nextdisabler').css({'visibility':'visible'});
    

提交回复
热议问题