jQuery - Trigger click event on links with spacebar?

后端 未结 2 1987
北荒
北荒 2021-02-14 07:47

It looks like in most browsers, an treats both [spacebar] and [enter] as a click, but an link only treats [ente

相关标签:
2条回答
  • 2021-02-14 08:18

    There are the standard usability concerns.

    I think 'looks like' is key here. If someone is using a screen reader they will 'see' a link and act appropriately.

    If someone has javascript turned off the jquery function (obviously) won't run and they will also get link behaviour.

    Obviously you've already done the soul searching(!) over using a link like a button so it is a case of dealing with these two cases - screen reader and non-javascript.

    If you can't also simulate the button behaviour (on a link) for these two cases then you will be offering different people a different experience - which is a good reason not to use the function. Either the spacebar should fire every use of these link/buttons or none of them.

    0 讨论(0)
  • 2021-02-14 08:29

    I think the most important standard to maintain is not the browser's behaviour, but rather the user's expected response.

    If you have overriden the display of links by turning them into buttons, the user must be able to treat those "buttons" exactly as they would if it were a real button, otherwise you will confuse and irritate users who have spent years with this "learnt" behaviour.

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