为什么仅在粘贴到BROWSER的地址栏中时显示图片 [英] why picture is shown only if pasted to BROWSER's address bar

查看:89
本文介绍了为什么仅在粘贴到BROWSER的地址栏中时显示图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试将以下选项(1-4)之一放到页面上并加载它时,没有显示图片.
但是,当我将路径之一放入任何浏览器的地址栏(IE,FF,Chrome ..)时,浏览器便会显示图片.

为什么在加载页面时未显示图片,但如果将路径粘贴到BROWSER的地址栏中则显示DO?

1:< img alt =" src ="D:\ images \ img.png"/>
2:< img alt =" src ="D:/images/img.png"/>
3:< img alt =" src ="ftp://d:/images/img.png"/>
4:< img alt =" stc ="ftp://d:\ images \ img.png"/>



谢谢您.

When I tried to put one of the options below(1-4) to the page and load it, no pictured is shown.
But, when I put one of the paths to any browser''s address bar(IE,FF, Chrome..), so the browser DOES show the picture.

Why the picture isn''t shown when the page is loaded but DO shown if the path is pasted to BROWSER''s address bar?

1: <img alt="" src="D:\images\img.png" />
2: <img alt="" src="D:/images/img.png" />
3: <img alt="" src="ftp://d:/images/img.png" />
4: <img alt="" stc="ftp://d:\images\img.png" />



Thank you

推荐答案

这是因为,当您在img 标记中提供src 时,它是从应用程序所在的位置获取图像的相对路径,因此从Web服务器运行,因此localhost是您可以相对获取图像的唯一位置.

关于将src 粘贴到显示image浏览器地址栏的第二个问题是,它是直接从文件存储区获取的,而img没有.
That is because when you are providing src in img tag it''s fetching image relatively path from where your application is, Webapplication is running from webserver so localhost is the only location from where you can relatively fetch image.

The second question on pasting src to browser addressbar showing the image, is that it''s fetching directly from your file storage, img doesn''t.




src属性是图像的位置,标记无法理解本地计算机上的绝对路径,可以理解它是否是Internet地址,例如src ="http://localhost/Project/images /abc.png或相对路径src =" ../images/abc.png(在浏览器中运行时,该路径将链接到Internet地址)

安迪
Hi,

The src attribute is the location of the image, the tag cannot understand the absolutely path on local computer, it can be understand if it''s an internet address such as src= "http://localhost/Project/images/abc.png" or relative path src="../images/abc.png" (when run on the browser this path will link to internet address)

Andy





您是否尝试过使用相对路径:
Hi,


Have you tried to use relative paths:
src="..\images\img.png"  



当然,这是相对于您的html文档而言的.

或文件:前缀:



this is relative to your html document of course...

or the file: prefix:

src="file://D:/images/img.png" 



瓦莱里.



Valery.


这篇关于为什么仅在粘贴到BROWSER的地址栏中时显示图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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