常见问题主题 - 我有< a href =" javascript:somefunction()">什么 ... ? [英] FAQ Topic - I have <a href="javascript:somefunction()"> what ... ?

查看:78
本文介绍了常见问题主题 - 我有< a href =" javascript:somefunction()">什么 ... ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

----------------------------------------------- ------------------------

常见问题解答主题 - 我有< a href =" javascript :somefunction()what ...?

----------------------------- ------------------------------------------


无论你的其他问题是什么,这通常是一个非常糟糕的使用javascript伪协议。它的设计使得

函数可以返回一个新页面。例如:

``javascript :"< p> Hello< / p>" ''''。

使用它只是在单击链接时调用函数导致

在不支持javascript的用户代理中出错,或者

禁用javascript。相反,使用

``< a href =" something.html" onclick =" somefunction(); return false"'''

其中something.html是一个有意义的选择。或者,

将onclick事件放在另一个元素上,这样没有

JavaScript的用户甚至不知道它做了什么。

< a rel =nofollowhref =http://www.useit.com/alertbox/20021223.html\"target =_ blank> http://www.useit.com/alertbox/20021223.html

===

这样的发布每天自动发送一次。他们的b
目标是回答重复的问题,并将内容提供给社区进行持续评估/改进。完整的

comp.lang.javascript常见问题解答位于 http:/ /www.jibbering.com/faq/

FAQ工作人员是一群志愿者。

-----------------------------------------------------------------------
FAQ Topic - I have <a href="javascript:somefunction()"what ... ?
-----------------------------------------------------------------------

Whatever the rest of your question, this is generally a very bad
use of the javascript pseudo protocol. It was designed so that a
function could return a new page. For example:
`` javascript:"<p>Hello</p>" ''''.
Using it simply to call a function when a link is clicked causes
an error in user agents that do not support javascript, or have
javascript disabled. Instead, use
`` <a href="something.html" onclick="somefunction();return false"''''
where something.html is a meaningful alternative. Alternatively,
place the onclick event on another element so that users without
JavaScript aren''t even aware that it does anything.

http://www.useit.com/alertbox/20021223.html
===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://www.jibbering.com/faq/.
The FAQ workers are a group of volunteers.

推荐答案



FAQ server写道:

FAQ server wrote:

---------------- -------------------------------------------------- -----

常见问题解答主题 - 我有< a href =" javascript :somefunction()" what ...?

------------------------------------------------ -----------------------


无论你的其他问题是什么,这通常是非常糟糕的/>
使用javascript伪协议。
-----------------------------------------------------------------------
FAQ Topic - I have <a href="javascript:somefunction()"what ... ?
-----------------------------------------------------------------------

Whatever the rest of your question, this is generally a very bad
use of the javascript pseudo protocol.



除非您正在编写书签(请参阅定义)。在这样的

的情况下,将其余代码包含在

" void"中总是一个好主意。运营商确保UA永远不会导航到代码的

输出(例如出现错误):

a href =" javascript :void(其余的你的代码)

使用javascript :伪协议用于伪链接(因此链接

的唯一目的是触发一些脚本在同一页面上执行)

应该避免。

Unless you are programming a bookmarklet (see the definition). In such
case it is always a good idea to enclose the rest of your code into
"void" operator to ensure that the UA will never "navigate" to the
output of your code (in case of error for example):
a href="javascript:void(the rest of your code)"
The usage of javascript: pseudo-protocol for pseudo-links (thus links
with the only purpose to trig some script execution on the same page)
should be avoided.


VK在9/6/2006 2:29上说了以下内容AM:
VK said the following on 9/6/2006 2:29 AM:

FAQ server写道:
FAQ server wrote:

> ---------- -------------------------------------------------- -----------
常见问题主题 - 我有< a href =" javascript :somefunction()什么......?
-------------------------------------------------- ---------------------

无论你的其他问题是什么,这一般都是非常糟糕的使用javascript伪协议。
>-----------------------------------------------------------------------
FAQ Topic - I have <a href="javascript:somefunction()"what ... ?
-----------------------------------------------------------------------

Whatever the rest of your question, this is generally a very bad
use of the javascript pseudo protocol.



除非您正在编写书签(请参阅定义)。在这样的

的情况下,将其余代码包含在

" void"中总是一个好主意。运营商确保UA永远不会导航到代码的

输出(例如出现错误):

a href =" javascript :void(其余的你的代码)"


Unless you are programming a bookmarklet (see the definition). In such
case it is always a good idea to enclose the rest of your code into
"void" operator to ensure that the UA will never "navigate" to the
output of your code (in case of error for example):
a href="javascript:void(the rest of your code)"



毫无疑问,这是一个糟糕的建议。更好的建议是*永远不要*

把javascript :放在一个href中,把它放在一个onclick事件处理程序中,这就是

*精确*常见问题解答说要做什么。

That is, without a doubt, bad advice. The better advice is to *never*
put javascript: in an href, put it in an onclick event handler which is
*precisely* what the FAQ says to do.


使用javascript :伪链接用于伪链接(因此链接

的唯一目的是在同一页面上触发一些脚本执行)

应该避免。
The usage of javascript: pseudo-protocol for pseudo-links (thus links
with the only purpose to trig some script execution on the same page)
should be avoided.



那么为什么关于将它包装在void运算符中的荒谬废话呢?


-

Randy

机会有利于准备好的心灵

comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组每周

Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /

Then why the nonsensical crap about wrapping it in a void operator?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Randy Webb写道:
Randy Webb wrote:

毫无疑问,糟糕的建议。更好的建议是*永远不要*

把javascript :放在一个href中,把它放在一个onclick事件处理程序中,这就是

*精确*常见问题解答说要做什么。
That is, without a doubt, bad advice. The better advice is to *never*
put javascript: in an href, put it in an onclick event handler which is
*precisely* what the FAQ says to do.



这个常见问题解答是在很久以前编写的,之后才开始使用bookmarklet成为优秀且流行的技术。因此它拒绝使用

... href =" javascript :..就这样。这就像采取规则不要

过马路,除非你看到绿灯。并且由它构成不要过去街头,不要过去......,而是......


clj可能会尝试坚持一些首选的编码方式,但是尝试b $ b来关闭整个技术看起来很有趣。

This FAQ was written eons ago, before bookmarklets became
well-established and popular technologies. Therefore it denies the use
of ...href="javascript:.. as such. It is like take the rule "do not
cross the street unless you see the green light" and made of it "do not
cross the street, never..."

clj may try to insist on some preferred ways of coding, but an attempt
to "close" an entire technologies seems funny.


那么为什么关于将它包装在void运算符中的无意义的废话呢?
Then why the nonsensical crap about wrapping it in a void operator?



在这个小组中已经多次解释过这个问题,并且第一次由Brendan解释

Eich在Netscapes的JavaScript参考中(1.2和1.3) )。您可能希望

搜索此组档案。

That was explained many times in this group, and first time by Brendan
Eich in Netscapes''s JavaScript reference (1.2 and 1.3). You may want to
search this group archives.


这篇关于常见问题主题 - 我有&lt; a href =&quot; javascript:somefunction()&quot;&gt;什么 ... ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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