Disable link using javascript

前端 未结 2 869
逝去的感伤
逝去的感伤 2021-01-14 06:13

I have following HTML and would like to disable the link using javascript.



        
相关标签:
2条回答
  • 2021-01-14 06:44

    I don't think the 'disable' attribute will work on links, it work mostly on form elements such as inputs, textarea, button, etc.

    But as @idealmachine said normal links <a> can be disabled by returning false 'return false' in javascript/jquery.

    0 讨论(0)
  • 2021-01-14 06:59
    document.getElementById("uc_ii_lnkInstall").onclick = function() { return false; };
    

    The return value of false in the old-style event handler prevents the default action (i.e. loading the javascript: URL).

    If you want to gray out the image link, you would also need to swap out the image's src URL with one pointing to a grayed-out version of the icon and change the text's color using .style.color = "gray";.

    0 讨论(0)
提交回复
热议问题