'javascript:'前缀何时有效? [英] When is the 'javascript:' prefix valid syntax?

查看:116
本文介绍了'javascript:'前缀何时有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以对< a> 标记中的网址使用javascript:pseudo协议。但是,我注意到Firefox和IE都允许' javascript:'在< script> 标签。这是有效的语法吗?它是否会改变范围规则?

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屋!

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