< img src ="#">在HTML中意味着什么? [英] <img src="#"> Means in HTML?

查看:512
本文介绍了< img src ="#">在HTML中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的HTML中有以下代码:

I do have the following code in my HTML:

<img src="#" alt="image alternative text" />

src =#均值?因为在HTML中,图像标签不能包含空的 src 属性。如果我们没有这个属性,visual studio 2012会提出一个建议。

What does src="#" mean? Because in HTML, I cannot have empty src attribute for an image tag. And if we do not have that attribute, visual studio 2012 will throw a suggestion.

谢谢

Thanks

推荐答案

如果您不想使用src属性加载任何图像(稍后可能会动态加载图像),则需要将src设置为空。但是,当你这样做时,浏览器仍然会向服务器发送调用。

When you don't want any image to be loaded using src attribute (probably load the image dynamically later), you need to set src empty. But when you do that, browsers still send calls to server.

空src的浏览器行为(来源: http://developer.yahoo.com/performance/rules.html

Browser behavior for empty src (Source: http://developer.yahoo.com/performance/rules.html)


Internet Explorer向页面
所在的目录发出请求。 Safari和Chrome向本身的实际页面
发出请求。 Firefox 3和更早版本的行为与Safari和
Chrome相同,但版本3.5解决了此问题[错误444931]并且不再有
发送请求。当遇到空白图像src时,Opera不会执行任何操作。

Internet Explorer makes a request to the directory in which the page is located. Safari and Chrome make a request to the actual page itself. Firefox 3 and earlier versions behave the same as Safari and Chrome, but version 3.5 addressed this issue[bug 444931] and no longer sends a request. Opera does not do anything when an empty image src is encountered.

为了避免不必要的服务器调用,使用空的src,可以使用 src =#,它形成一个哈希URL并且哈希URL不会被发送到服务器。

To avoid the unnecessary call to server, instead of using empty src, src="#" could be used which forms a hash url and hash urls are not sent to server.

让我们说基地网址是: http://mysite.com/myapp/

Let's say base url is : http://mysite.com/myapp/

src = - >绝对网址: http://mysite.com/myapp/

src="" -> Absolute url: http://mysite.com/myapp/

src =# - >绝对网址: http://mysite.com/myapp/

src="#" -> Absolute url: http://mysite.com/myapp/#

这篇关于&lt; img src =&quot;#&quot;&gt;在HTML中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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