'javascript:methodName()'的用法是什么?在锚链接? [英] What is the use of 'javascript:methodName(); in an anchor link?

查看:947
本文介绍了'javascript:methodName()'的用法是什么?在锚链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

javascript:methodName()的用法是什么?在锚链接中?



我在一些代码中看到了以下内容。什么是javascript:的使用?

 < a href =#onclick =javascript:getUserName() />点击< / A> 

它在两种情况下都有效(包括和不包含javascript:)条件。 b $ b

解决方案

在这种情况下, .mozilla.org / zh-CN / docs / Web / JavaScript / Reference / Statements / labelrel =nofollow noreferrer> label :


提供一个带有标识符的语句,您可以使用 break continue 语句引用该标识符。例如,您可以使用标签来标识循环,然后使用 break continue 语句来指示程序是否应该中断循环或继续执行。


它在这种情况下是没有用的,而不是 javascript 你可以使用其他任何单词。



因为通常在 href 属性(其中 javas cript:是一个伪方案):

  href =javascript:getUserName()

但它在上有完全不同的含义* * / code >属性。



相关:你是否曾经需要指定'javascript:'在onclick?


What is the use of 'javascript:methodName(); in an anchor link?

I have seen the following in some code. What is use of the "javascript:"?

 <a href="#" onclick="javascript:getUserName()"/>Click</a>

It works if in both (with and without "javascript:") condition.

解决方案

In this case javascript: is a label:

Provides a statement with an identifier that you can refer to using a break or continue statement.

For example, you can use a label to identify a loop, and then use the break or continue statements to indicate whether a program should interrupt the loop or continue its execution.

It is of no use in this case and instead of javascript you could use any other word there.

It is probably only (mistakenly!) used because one typically sees this in the href attribute (where javascript: is a pseudo-scheme):

href="javascript:getUserName()"

but it has a totally different meaning in on* attributes.

Related: Do you ever need to specify 'javascript:' in an onclick?

这篇关于'javascript:methodName()'的用法是什么?在锚链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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