“javascript:”的重点是什么?在代码(而不是URL)? [英] What's the point of "javascript:" in code (not URLs)?
问题描述
我偶然发现了一些我以前从未见过的奇怪的事情:
I stumbled upon something strange that I never really seen before:
javascript:a=a+10;
上面的行似乎是正确的并且评价得很开心(至少在Firefox中),就像 javascript:
部分从未存在。
The line above seems to be correct and evaluates happily (at least in Firefox) just like if the javascript:
part never existed.
虽然我明白旧的 javascript的目的:在 style
< a href =../>
https://en.wikipedia.org/wiki/Dynamic_HTMLrel =noreferrer> DHTML ,我只是无法在纯JavaScript代码中弄清楚这个前缀的任何有用用法。
While I do understand the purpose of the old javascript:void(...)
style <a href=".."/>
used during the dark ages of DHTML, I just can't figure out any useful usage of this prefix in plain JavaScript code.
它有一些特殊含义吗?
推荐答案
javascript :
是一个标签。它应该用于识别循环,以便您可以使用 break javascript;
来突破它,但在这里被滥用。它是无害的,但是对于不是循环的语句添加标签可能不是一个好主意。
The "javascript:
" is a label. It's supposed to be used to identify a loop so that you could then use "break javascript;
" to break out of it, but is being misused here. It's harmless, but probably not a good idea to add a label to a statement that isn't a loop.
这篇关于“javascript:”的重点是什么?在代码(而不是URL)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!