< img src ="#">在HTML中意味着什么?

编程入门 行业动态 更新时间:2024-10-28 17:26:19
本文介绍了< 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的浏览器行为(来源: developer.yahoo/performance/rules.html )

Browser behavior for empty src (Source: developer.yahoo/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.

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

Let's say base url is : mysite/myapp/

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

src="" -> Absolute url: mysite/myapp/

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

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

更多推荐

&lt; img src =&quot;#&quot;&gt;在HTML中意味着什么?

本文发布于:2023-06-07 03:52:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/560847.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:意味着什么   img   lt   amp   src

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!