html图像没有出现

时间:2015-03-23 00:04:37

标签: javascript html

<!DOCTYPE html>
<html>
<head> 
<title> Cookie Clicker! </title>
<script type="text/javascript">
var logAt=function(id,message){
document.getElementById(id).innerHTML=message;
};
</script>
</head>
<body>
<h1> Cookie Clicker </h1>
<p> Keep collecting cookies and start your very own sweet empire!</p>
<p>
<div id="cookiesPerSecond"> </div>
<button type="button" onClick="getCookie()"><img src="http://thinkprogress.org/politics/2011/04/26/161276/penn-parents-cookies-cuts/" alt="Cookie"
style="width:304px;height:228px"></button>
<h3 id="cookies">Cookies:0 </h3>
</p>
<script type="text/javascript">
var cookies=0;
var cookiesPerSecond=0;
function getCookie(){
cookies+=1;
logAt("cookies","Cookies:"+cookies);
};
</script>
</body>
</html>

按钮内部的图像未显示,默认为&#34; alt&#34;。我在记事本上编程,并在chrome中打开它。我该怎么做才能让它发挥作用?

1 个答案:

答案 0 :(得分:0)

您链接的内容不是指向直接图片的链接。您需要直接链接到图像。这是您需要更改的链接:

<img src="http://thinkprogress.org/politics/2011/04/26/161276/penn-parents-cookies-cuts/"

将其更改为:

<img src="http://d35brb9zkkbdsd.cloudfront.net/wp-content/uploads/2011/04/cookie.gif"

此外,像用户Roko C. Bulijan所说,你需要使用CSS使其成为背景图像,否则它将不会出现。