disable a hyperlink using jQuery

后端 未结 11 1678
悲&欢浪女
悲&欢浪女 2020-11-29 02:06
Click me

I did

$(\'.my-link\').attr(\'disabled\', true);
11条回答
  •  一生所求
    2020-11-29 02:43

    I know it's an old question but it seems unsolved still. Follows my solution...

    Simply add this global handler:

    $('a').click(function()
    {
         return ($(this).attr('disabled')) ? false : true;
    });
    

    Here's a quick demo: http://jsbin.com/akihik/3

    you can even add a bit of css to give a different style to all the links with the disabled attribute.

    e.g

    a[disabled]
    {
        color: grey; 
    }
    

    Anyway it seems that the disabled attribute is not valid for a tags. If you prefer to follow the w3c specs you can easily adopt an html5 compliant data-disabled attribute. In this case you have to modify the previous snippet and use $(this).data('disabled').

提交回复
热议问题