'javascript:'前缀何时有效? [英] When is the 'javascript:' prefix valid syntax?
问题描述
我知道您可以对< a>
标记中的网址使用javascript:pseudo协议。但是,我注意到Firefox和IE都允许' javascript:
'在< script> $ c中的javascript代码之前$ c>标签。这是有效的语法吗?它是否会改变范围规则?
I know that you can use a javascript: pseudo protocol for URLs in an <a>
tag. However, I've noticed that Firefox and IE will both allow 'javascript:
' to precede javascript code within a <script>
tag. Is this valid syntax? Does it change the scoping rules?
示例:
我已经多次看到过:
Examples: I've seen this many times:
<a onclick="javascript:alert('hello world!');">Hello World!</a>
但这是合法/有效的语法并且它做了什么特别的事情:
But is this legal/valid syntax and does it do anything special:
<script type="text/javascript">
javascript:alert('hello world!');
</script>
推荐答案
href之外
属性(它是协议说明符), name :只创建标签(例如可以使用继续
或中断
)。
Outside of the href
attribute (where it is a protocol specifier), name: just creates a label (such as one might use with a continue
or break
).
这篇关于'javascript:'前缀何时有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!