JavaScript伪协议实际上做了什么? [英] What does the JavaScript pseudo protocol actually do?

查看:110
本文介绍了JavaScript伪协议实际上做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

换句话说,

onclick="myFunction()"

onclick="JavaScript:myFunction()"


推荐答案

JavaScript: TYPE / LABEL / PREFIX(找不到它的实际名称)在事件处理程序中只提供一个目的

The JavaScript: TYPE/LABEL/PREFIX (could not find the actual name for it) in the event handler serves one purpose only:

在IE浏览器中, IFF 页面上的第一个脚本是 JavaScript,页面其余部分的内联JavaScript已经(仍然有?) code> javascript:为它添加前缀。

In IE, IFF the FIRST script on the page is NOT JavaScript, inline JavaScript on the rest of the page had (still has?) to have javascript: prefixing it.

不要将其与href中的 javascript: 协议混淆(顺便也应该避免)。只有在AREA标记中的旧网景中才需要 href =javascript:...。当你看到 href =javascript:void(0)有人需要使用 onclick =....; return false相反,除非他们把它放在那里提醒用户该链接是一个javascript驱动的链接。如果关闭JS,它将失败。

It is not to be confused with the javascript: protocol in the href (which by the way also should be avoided). href="javascript:..." is only ever needed in old netscapes in the AREA tag. When you see the href="javascript:void(0)" someone needs to use onclick="....; return false" instead unless they put it there to alert the user that the link is a javascript driven one. It will fail if JS is turned off.

我查找了msdn的官方文档,但这里有讨论支持我:

I looked for the official documentation from msdn, but here are discussions to back me up:

从Javascript调用VBScript


Internet Explorer默认使用它解析的第一个脚本元素
的语言。因此,如果第一个脚本元素是javascript,则不应该在
中在事件处理程序中指定javascript:。

Internet Explorer defaults to the language of the first script element it parses. So if the first script element is javascript, you shouldn't need to specify "javascript:" in your event handler.

http://www.webdeveloper.com/forum/archive /index.php/t-135462.html


你必须告诉IE你正在使用VBS和JScript,否则
假设在这个实例中所有函数都是VBS。要么在页面顶部添加
(空?)JavaScript脚本元素,要么在
onchange上使用jscript:protocol。
onchange =jscript:location.hash = this [this.selectedIndex] .value;

You have to tell IE you are using VBS AND JScript, otherwise the assumption is all functions are VBS in this instance. Either add a (empty?) JavaScript script element [at the top of your page] or use the jscript: protocol on the onchange. onchange="jscript:location.hash=this[this.selectedIndex].value;"

示例

<html>
<head>
<script language="VBScript">
' some vbscript here forces the default language
' of the page to be VBScript and not jScript/JavaScript
</script>
</head>
<body onload="javascript:alert('I am inline in an event handler - boo me')">
.
.
<a href="..." onclick="javascript:alert('and so am I'); return false">Click</a>
.
<a href="javascript:alert('javascript: PROTOCOL is NOT the same (but avoid it too)')">
  Click
</a>


</body>
</html> 

这篇关于JavaScript伪协议实际上做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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