HTML anchor link - href and onclick both?

后端 未结 4 2033
耶瑟儿~
耶瑟儿~ 2020-11-28 21:38

I want to author an anchor tag that executes some JavaScript and then proceeds to go wherever the href was taking it. Invoking a function that executes my JavaS

4条回答
  •  佛祖请我去吃肉
    2020-11-28 22:19

    If the link should only change the location if the function run is successful, then do onclick="return runMyFunction();" and in the function you would return true or false.

    If you just want to run the function, and then let the anchor tag do its job, simply remove the return false statement.

    As a side note, you should probably use an event handler instead, as inline JS isn't a very optimal way of doing things.

提交回复
热议问题