“[removed]void(0);” vs “return false” vs “preventDefault()”

前端 未结 8 1278
滥情空心
滥情空心 2020-11-28 19:44

When I want some link to not do anything but only respond to javascript actions what\'s the best way to avoid the link scrolling to the top edge of the page ?
I know sev

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 20:10

    I tend to prefer using return false, as that gives the option to give the user a choice whether to continue that action, such as shown here, in quirksmode:

    http://www.quirksmode.org/js/events_early.html#default

    It's simple, it's old, but it works well, cross-browser, regardless of the version of javascript.

提交回复
热议问题