这个问题已经在这里有了答案: > Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”? 53个
如下所示对锚标记的累积影响是什么:
/**
* This function will create a popup iFrame (not a complete function)
*/
function CreateIframe() {
// This is just a sample and not complete code
var iframe = document.createElement('iframe');
// Initialize and create iFrame and popup iFrame
}
<a href="javascript:void(0)" onclick="CreateIframe();return false;" >Click here!</a>
解决方法:
关于void(0):
由@rahul在What does “javascript:void(0)” mean?中定义
The void operator evaluates the given expression and then returns undefined.
The void operator is often used merely to obtain the undefined primitive value, usually using “void(0)” (which is equivalent to “void 0”). In these cases, the global variable undefined can be used instead (assuming it has not been assigned to a non-default value).
“您之所以要使用链接的href这样做是因为,通常,一个javascript:URL会将浏览器重定向到评估该JavaScript的结果的纯文本版本.但是,如果结果未定义,则浏览器停留在同一页面上.void(0)只是可能评估为未定义的最小脚本.”
返回false:
就像event.preventDefault否定它一样.
如果您调用类似的函数:
<button type="submit" onclick="return some_function();"></button>
some_function返回false;如果您调用提交,则提交不会发生..但是,调用提交时,返回true将继续提交.
就您而言,单击链接不会重定向您.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。