空锚,我找不到它的W3C规范 [英] Empty Anchors, I can't find a W3C specification for it

查看:66
本文介绍了空锚,我找不到它的W3C规范的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我对以下内容感到有些惊讶:

< a href ="#" ...


我发现一些关于网站的href标记的行应该指向一个

名称或者在XHTML中指向一个ID,

,但在这两种情况下,这似乎都不是有效的名称="#或者id ="" ...

我想知道为什么在线验证器在所有情况下都允许这样做.DOCUMENT

类型。


有人可以给我任何W3C文件的确切链接,我可以在这里查看这是有效的吗?我发现只有一些网站会产生后果

这是无效的。


彼得

解决方案

Scripsit La ********* @ gmail.com


我对以下内容感到有些惊讶:

< a href ="#" ...



只是不要使用它们,mm''ay?但这是一个实际问题。形式上,它是定义良好的



我发现一些关于网站的href标记的行应该指向

名称或XHTML到ID,



错误。 href _attribute_值是_URL_。您需要检查当前的

URL规范,以查看允许作为URL的内容。


有人可以给我一个明确的链接W3C文件在哪里我可以

看到这个有效吗?



相关HTML规范中的相关DTD意味着

有效,就像href =some%¤!¤ 我刚刚决定放在这里的东西!

有效。在这种情况下,有效性意味着很少。


-

Jukka K. Korpela(Yucca)
http://www.cs.tut.fi/~jkorpela/


La ********* @ gmail。 com < La ********* @ gmail.comwrote:


我对以下内容感到有些惊讶:

< a href ="#" ...



是的,这通常可以在网上找到。一般来说,这并没有任何意义,但因为网页的作者对JavaScript和事件处理程序(尤其是关于JavaScript)和事件处理程序的了解并不是很多。返回值

的onclick处理程序),他使用这个空片段标识符

解决了他的错误和错误的JavaScript代码的一些副作用。


通常你会发现这些空片段标识符和

onclick处理程序,如下面的代码所示:


< ; a href ="#" onclick =" someJavaScriptCode()">点击此处< / a>


在这种情况下,点击链接将执行

的javascript代码首先是onclick处理程序。然后hanlder可以返回一个值(true,false)

告诉浏览器链接的默认操作是否也必须执行
(这意味着打开页面通过

href属性引用。所以返回值false强制浏览器不要打开链接。但是不知道这个的网络作者不会在事件处理程序中返回任何值,因此浏览器也会执行

默认操作。链接。这意味着打开href属性中给出的页面

。所以这些网络作者倾向于使用这个

"#"在href属性中,以防止浏览器没有打开新的

页面。但这也有一些负面影响:一些浏览器将页面滚动到页面顶部,假设空片段标识符标识

文档的顶部。


我发现一些关于网站的href标记的行应该指向一个

名称,或者在XHTML中指向一个ID,


不,href属性必须始终包含URI值。片段

标识符(#之后的部分)也是URI值的一部分。所以

"#"是一个相对URL,可以解析为

文档本身的绝对URL。这就是为什么这个#的原因。是工作:它

告诉浏览器加载已经显示的页面,这个

通常会被浏览器解释为什么都不做(因为

页面已经显示)。但正如我上面所说,一些浏览器滚动到

顶部,有些甚至可能会重新加载当前显示的页面。

-

Alexander


4月7日14:08,Jukka K. Korpela < jkorp ... @ cs.tut.fiwrote:


Scripsit Lastwebp ... @ gmail.com:


我对以下内容感到有些惊讶:

< a href ="#" ...



只是不要使用它们,mm''ay?但这是一个实际问题。形式上,它是定义良好的



我发现一些关于网站的href标记的行应该指向

名称或XHTML到ID,



错误。 href _attribute_值是_URL_。您需要检查当前的

URL规范,以查看允许作为URL的内容。


有人可以给我一个明确的链接W3C文件在哪里我可以

看到这个有效吗?



相关HTML规范中的相关DTD意味着

有效,就像href =some%¤!¤ 我刚刚决定放在这里的东西!

有效。在这种情况下,有效性意味着很少。


-

Jukka K. Korpela(Yucca) http://www.cs.tut.fi/~jkorpela/



谢谢,我在W3C文档的错误位置搜索,现在我发现
http://www.w3.org/Addressing/URL/4_2_Fragments.html 和其他一些

的地方。

In我的观点在锚定义中仍有问题

for XHTML,但没问题。


彼得


Hello,
I am little surprised about the following:
<a href="#" ...

I found some lines about the href tag for a site should point to an
name or in XHTML to an ID,
but in both cases this seems to be not valid name="#" or id=""...
And I wonder why the online validator allow this in all cases.DOCUMENT
types.

Can someone give me a definitive link to any W3C document where I can
see this is Valid? I found only some sites where the consequence would
be this is not valid.

Peter

解决方案

Scripsit La*********@gmail.com:

I am little surprised about the following:
<a href="#" ...

Just don''t use them, mm''kay? But that''s a practical issue. Formally, it is
well-defined.

I found some lines about the href tag for a site should point to an
name or in XHTML to an ID,

Wrong. The href _attribute_ value is a _URL_. You need to check the current
URL specifications to see what is allowed as a URL.

Can someone give me a definitive link to any W3C document where I can
see this is Valid?

The relevant DTD in a the relevant HTML specification implies that it is
valid, just as href="some %¤!¤"9^ stuff I just decided to put here!" is
valid. Validity means very little in this context.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/


La*********@gmail.com <La*********@gmail.comwrote:

I am little surprised about the following:
<a href="#" ...

Yes, this is often found in the web. In general this doesn''t make any
sense but because the author of the web page doesn''t know very much
about JavaScript and event handlers (especially about the return value
of the "onclick" handler), he uses this empty fragment identifier to
workaround some side effects of his bad and buggy JavaScript code.

Usually you''ll find these empty fragment identifier together with an
onclick handler like in the following code:

<a href="#" onclick="someJavaScriptCode()">click here</a>

In this case clicking the link will execute the javascript code of the
onclick handler first. The hanlder can then return a value (true, false)
to tell the browser if the default action of the link must be also
executed (which means opening the page that is referenced through the
href attribute). So returning the value "false" forces the browser not
to open the link. But web authors who don''t know about this don''t return
any value in the event handler and so the browser is also executing the
default action for the link. Which means opening the page that is given
in the href attribute. And so these web authors tend to use this
"#" in the href attribute to prevent that the browser doesn''t open a new
page. But this has also some negative side effects: some browsers scroll
the page to the top, assuming the empty fragment identifier identifies
the top of the document.

I found some lines about the href tag for a site should point to an
name or in XHTML to an ID,

No, the href attribute must always contain an URI value. The fragment
identifier (the part after the "#") is also part of an URI value. So
"#" is a relative URL which can be resolved to the absolute URL of the
document itself. This is the reason why this "#" is "working": it
tells the browser to load the page which is already displayed and this
will usually be interpreted by the browser to do nothing (because the
page is already shown). But as I said above, some browsers scroll to the
top, some may even reload the page that is currently displayed.
--
Alexander


On 7 Apr., 14:08, "Jukka K. Korpela" <jkorp...@cs.tut.fiwrote:

Scripsit Lastwebp...@gmail.com:

I am little surprised about the following:
<a href="#" ...


Just don''t use them, mm''kay? But that''s a practical issue. Formally, it is
well-defined.

I found some lines about the href tag for a site should point to an
name or in XHTML to an ID,


Wrong. The href _attribute_ value is a _URL_. You need to check the current
URL specifications to see what is allowed as a URL.

Can someone give me a definitive link to any W3C document where I can
see this is Valid?


The relevant DTD in a the relevant HTML specification implies that it is
valid, just as href="some %¤!¤"9^ stuff I just decided to put here!" is
valid. Validity means very little in this context.

--
Jukka K. Korpela ("Yucca")http://www.cs.tut.fi/~jkorpela/

Thanks, I searched at the wrong place in the W3C docu, now I found
http://www.w3.org/Addressing/URL/4_2_Fragments.html and some other
places.
In my opinon there is still something wrong in the anchor definition
for XHTML, but ok.

Peter


这篇关于空锚,我找不到它的W3C规范的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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