'javascript:'前缀何时有效?

编程入门 行业动态 更新时间:2024-10-27 17:20:54
本文介绍了'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:'前缀何时有效?

本文发布于:2023-11-13 21:35:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585383.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:前缀   javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!