How do I make a link unclickable?

前端 未结 11 692
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 19:37

Is there some CSS property or something that I can use with my anchor tag so as to make it unclickable or I HAVE to do stuff in code behind to get what I want?

11条回答
  •  既然无缘
    2020-12-08 20:32

    You can use

    disabled="disabled"
    

    in the anchor tag, I believe - that's what I do on csharpindepth.com, anyway. I wouldn't like to swear to how widely supported it is, admittedly - you probably want to check that. Seems okay on Chrome, IE and Firefox though. I don't know if there's an equivalent just in CSS.

    Note that I believe this will make the link visibly unclickable (however the browser wants to do that) rather than just not do anything.

    EDIT: I've just tried this on a local file, and it doesn't work... whereas it definitely works on csharpindepth.com. Worth trying then, but also probably worth looking at other approaches :)

    EDIT: As BoltClock notes, this isn't strictly valid HTML - which may mean it will only work in quirks mode, for example. (That could explain my failure to produce it locally.)

    You're probably better off with a JavaScript solution along with a CSS style to change the link appearance... but I'll leave this answer here just for the record.

提交回复
热议问题