What's the effect of adding void(0) for href and 'return false' on click event listener of anchor tag?
本问题已经有最佳答案,请猛点这里访问。
以下内容对锚标签的累积影响是什么?
1 2 3 4 5 6 7 8 9 | /** * 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 } |
1 | Click here! |
关于
正如@rahul在"javascript:void(0)"中定义的那样?
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)只是计算为未定义的最小脚本。"
像是一个拒绝它的
如果调用如下函数:
1 | <button type="submit" onclick="return some_function();"></button> |
而
在您的情况下,单击链接时不会重定向。