Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

javascript - “ javascript:void(0)”是什么意思?(What does “javascript:void(0)” mean?)

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

我已经看过很多次href ,但是我不知道这到底意味着什么。

  ask by omg translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The void operator evaluates the given expression and then returns undefined .

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

The void operator is often used merely to obtain the undefined primitive value, usually using “ void(0) ” (which is equivalent to “ void 0 ”).

(void运算符通常仅用于获取undefined原始值,通常使用“ void(0) ”(等效于“ void 0 ”)。)

In these cases, the global variable undefined can be used instead (assuming it has not been assigned to a non-default value).

(在这些情况下,可以改用undefined全局变量(假设尚未将其分配给非默认值)。)

An explanation is provided here: void operator .

(这里提供了一个解释: void operator 。)

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.

(您之所以要使用链接的href这样做是因为,通常,一个javascript: URL会将浏览器重定向到评估该JavaScript的纯文本版本。)

But if the result is undefined , then the browser stays on the same page.

(但是,如果结果undefined ,则浏览器将停留在同一页面上。)

void(0) is just a short and simple script that evaluates to undefined .

(void(0)只是一个简短的脚本,其结果为undefined 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...