【发布时间】:2014-08-28 00:24:07
【问题描述】:
此代码未按预期工作
<html>
<head><title>alert()</title>
<script type="text/javascript">
function greeting()
{
var name=prompt("what's your name?","your name");
if(name){
alert("hi, " + name + " welcome to this page");
document.getElementById("im").src="F:\wallpapers\a.jpg";
}
}
</script>
</head>
<body onload="alert('hi, this is the alert() function');">
<img id="im" src="F:\wallpapers\Ubuntu_wallpaper__1_by_leroi14.jpg" onclick="greeting();" /></body>
</html>
document.getElementById("im").src="F:\wallpapers\a.jpg" 在给定绝对路径时不显示图像。 但如果图像与此文件位于同一文件夹中,则它可以工作。 谁能帮忙?
【问题讨论】:
-
你是在本地运行还是在服务器上运行?您的图像源真的不应该包含驱动器号。
-
我正在本地运行它...图像在另一个文件夹中。
-
你有图片文件夹吗?您应该使用一个,并将其放在您的服务器文件夹中。然后你可以使用类似的东西:
src="/images/wallpaper.jpg"
标签: javascript