javascript anchor avoid scroll to top on click

前端 未结 5 1628
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 14:47

I created a function in javascript that i add to an anchor as such

javascript :

somefunction = function () {alert(\'foo\')}

html :

5条回答
  •  庸人自扰
    2020-12-08 15:22

    You need to make somefunction() return false, or you need to explicitly add return false to your onclick handler. For example:

    anchor
    

    This will have the browser ignore the href portion of the link when someone clicks on it.

提交回复
热议问题