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 重新
基础教程推荐
- 如何在特定日期之前获取消息? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
