什么是“javascript:void(0)”意思? [英] What does "javascript:void(0)" mean?

查看:184
本文介绍了什么是“javascript:void(0)”意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<a href="javascript:void(0)" id="loginlink">login</a>

我见过这样的 href s很多时间,但我不知道究竟是什么意思。

I've seen such hrefs many times, but I don't know what exactly that means.

推荐答案


void 运算符计算给定的
表达式,然后返回 undefined

void 运算符通常仅用
来获取 undefined 原始
值,通常使用 void(0)(其中
相当于 void 0 )。在这些
的情况下,全局变量 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).

此处提供了解释: void operator

An explanation is provided here: void operator.

你原因是什么d想要通过链接的 href 执行此操作通常, javascript: URL会将浏览器重定向到评估该JavaScript的结果的纯文本版本。但如果结果是 undefined ,则浏览器将保持在同一页面上。 void(0)只是一个简短的简单脚本,其结果为 undefined

The reason you’d want to do this with the href of a link is that normally, a javascript: URL will redirect the browser to a plain text version of the result of evaluating that JavaScript. But if the result is undefined, then the browser stays on the same page. void(0) is just a short and simple script that evaluates to undefined.

这篇关于什么是“javascript:void(0)”意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆