How to prevent reload with onclick without quot;#quot;?(如何防止在没有“#的情况下使用 onclick 重新加载?)
问题描述
我希望通过链接添加一些说明 - onclick 调用一个显示简单警报框的脚本.如果我真的喜欢这样......
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>
即使返回 false,页面也会重新加载,如果我这样做了...
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?
推荐答案
调用后返回false:
Return false after the call:
<a href="" onclick="ajudaUpload();return false;">tipos permitidos</a>
或者如果你的函数返回 false 那么你可以返回函数的结果:
Or if your function returns false then you can return the result of the function:
<a href="" onclick="return ajudaUpload();">tipos permitidos</a>
仅在函数中返回 false 是不够的,您需要从点击处理程序中实际返回 false.
It's not enough to just return false in the function, you need to actually return false from the click handler.
这篇关于如何防止在没有“#"的情况下使用 onclick 重新加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何防止在没有“#"的情况下使用 onclick 重新


- 失败的 Canvas 360 jquery 插件 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Fetch API 如何获取响应体? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01