How to prevent reload with onclick without “#”?

2019-01-22 14:01发布

I wish to put some instructions with a link - onclick calling a script that display a simple alert box. If I did like this...

<label for="arquivo">Máximo de 1MB, observe os <a href="" onclick="ajudaUpload();">tipos permitidos</a>.</label>

the page is reloaded even with a return false, and if I did like this...

<label for="arquivo">Máximo de 1MB, observe os <a href="#" onclick="ajudaUpload();">tipos permitidos</a>.</label>

with the "#" symbol, the page is scrolled to the top and "#" is added to query string. Is there a third way to do it without reloading, scrolling and garbage?

7条回答
甜甜的少女心
2楼-- · 2019-01-22 14:39

You can use .preventDefault() method, or return false, or remove the HREF tag all together. Either should work just fine.

Vc nao deviar estar usando onclick dessa forma pra comecar. Ja eh bem antigo e nao se usa assim mais.

查看更多
登录 后发表回答