HTML <img> 标签不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14540517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML <img> tag is not working
提问by Aman Khanna
I am using following simple HTML :
我正在使用以下简单的 HTML :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<body>
<img src="loading.gif" alt="MISSING GIF">
<img src="j.JPG" alt="MISSING JPG">
</body>
</html>
loading.gif
and j.jpg
are present in same directory as html file. loading.gif
is displayed fine in ie 8 but j.jpg
doesn't load.
loading.gif
并j.jpg
与 html 文件位于同一目录中。loading.gif
在 ie 8 中显示良好,但j.jpg
无法加载。
When I use firefix, both images display correctly.
当我使用 firefix 时,两个图像都显示正确。
Please help
请帮忙
回答by Kevin Bowersox
Check that JPG
file extension is uppercase in the file system. I suspect that it is lowercase. Also be sure to close the image tag.
检查JPG
文件系统中的文件扩展名是否为大写。我怀疑它是小写的。还要确保关闭图像标签。
<img src="j.jpg" alt="MISSING JPG"/>
回答by Novakim
I had the same problem, i deiscovered that when working with wordpress you should use this code for images:
我遇到了同样的问题,我发现在使用 wordpress 时,您应该对图像使用以下代码:
<img src="<?php bloginfo('template_directory'); ?>/images/example.jpg" alt = "example">
回答by user3371805
Was the img file originally in another extension? If so, revert to the original extension.
img 文件最初是在另一个扩展名中吗?如果是这样,请恢复到原始扩展名。
I took a screenshot on my Windows PC in .png format. I changed the extension to .jpg (thinking it would work the same as my Mac). IE didn't like it, but Firefox was fine with it.
我在我的 Windows PC 上以 .png 格式截取了屏幕截图。我将扩展名更改为 .jpg(认为它可以和我的 Mac 一样工作)。IE 不喜欢它,但 Firefox 很好。
<img src="1.jpg" />
I changed the extension back to .png, and it worked fine in both browsers.
我将扩展名改回 .png,它在两种浏览器中都运行良好。
<img src="1.png" />
回答by A.Goutam
<img src="loading.gif" alt="MISSING GIF">
will be like this
会是这样
<img id="ImgEmployee" src="Photos/loading.gif" alt="MISSING GIF" />
回答by Ian Devlin
Is it broken in IE9/10 too?
它在 IE9/10 中也被破坏了吗?
Also, if the code you posted above is exactly what's in your file, you have an incorrect character (`) right before the doctype declaration.
此外,如果您上面发布的代码正是您的文件中的代码,那么您在 doctype 声明之前有一个不正确的字符 (`)。
Internet Explorer breaks when your HTML is wrong, browsers like Firefox are much more lenient and try and fix things for you.
当您的 HTML 错误时,Internet Explorer 会中断,像 Firefox 之类的浏览器要宽松得多,并会尝试为您修复问题。
回答by Ian Devlin
I think it is because of the specific images. Check if you have permission to use those files. I also had the same problem. I had two OS(Ubuntu and Windows) running and the image I was using was coming from Windows local disk. After I solved this permission issue, it worked.
我认为这是因为特定的图像。检查您是否有权使用这些文件。我也有同样的问题。我运行了两个操作系统(Ubuntu 和 Windows),我使用的映像来自 Windows 本地磁盘。在我解决了这个权限问题后,它起作用了。
回答by imRen
recently i was working in a web project using WAMP server. i placed my web site under c:/wamp/www/my_site
folder and referenced an image from this folder on a page. the image did not display. i referenced another image at desktop
...bingo, it worked. i think its the permission thing...
:)
最近我在一个使用 WAMP 服务器的网络项目中工作。我将我的网站放在c:/wamp/www/my_site
文件夹下,并在页面上引用了此文件夹中的图像。图像没有显示。我在desktop
...bingo 上引用了另一张图片,它奏效了。我认为这是许可的事情...... :)
回答by Subrat Saxena
Did you checked if there is some difference in the header? This happens sometimes that due to some GET requests header changes to something like this: {https:www.xyz.com/?id=blah-blah}. Now since no such file exist in the directory, the img tag remains clueless that actually where it had to look for the resource. You need to change send header again to the same page so that no GET request get connected to the address this time. Took me a long time to figure out.
您是否检查了标题中是否有一些差异?有时会发生这种情况,因为某些 GET 请求标头更改为以下内容:{https:www.xyz.com/?id=blah-blah}。现在因为目录中不存在这样的文件,img 标签仍然不知道它实际上必须在哪里寻找资源。您需要再次将发送标头更改为同一页面,以便这次没有 GET 请求连接到该地址。我花了很长时间才弄明白。
回答by Andrea Ligios
lowercase the extension, and close the img tags, you are using XHTML 1.0 Strict !
小写扩展名,并关闭 img 标签,您使用的是 XHTML 1.0 Strict !
<img src="loading.gif" alt="MISSING GIF" />
<img src="j.jpg" alt="MISSING JPG" />
EDIT: maybe you hit a IE8 bug... +1 to the question :)
编辑:也许您遇到了 IE8 错误...+1 问题:)
Let's try like this: using a page really XHTML 1.0 Strict compliant,
让我们试试这样:使用一个真正符合 XHTML 1.0 Strict 的页面,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>hi!</title>
</head>
<body>
<div>
j.JPG : <img src="j.JPG" alt="MISSING JPG" />
(upper case) <br/>
j.jPG : <img src="j.jPG" alt="MISSING JPG" />
(first lower case, others upper case <br/>
j.jpg : <img src="j.jpg" alt="MISSING JPG" />
(lower case) <br/>
</div>
</body>
</html>
create two copies of the file, so you will have the three files listed above. Then run the page in IE8 and tell us which one is working...
创建文件的两个副本,因此您将拥有上面列出的三个文件。然后在 IE8 中运行该页面并告诉我们哪个正在运行...