Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';我的HTML/JS页面上没有背景图片_Javascript_Image_Css_Background - Fatal编程技术网

Javascript Can';我的HTML/JS页面上没有背景图片

Javascript Can';我的HTML/JS页面上没有背景图片,javascript,image,css,background,Javascript,Image,Css,Background,这是代码,我无法获得蛋糕的图片或完整的html。我试过类似HTML的body background,我试过style,我试过js,都不管用。有趣的是,我已经在其他页面上测试了该图像,加载良好。我也尝试过用html、css、js修改背景色,它们都很好用。但是该死的图像无法加载。有什么想法吗 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Age

这是代码,我无法获得蛋糕的图片或完整的html。我试过类似HTML的body background,我试过style,我试过js,都不管用。有趣的是,我已经在其他页面上测试了该图像,加载良好。我也尝试过用html、css、js修改背景色,它们都很好用。但是该死的图像无法加载。有什么想法吗

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Age Calculator</title>
</head>
<body>


  <style>
    #myDiv {
      background-image: url('images/cake.png');
      background-size: cover;
    }

    </style>

<div id="myDiv">
<script>

//document.body.style.backgroundImage = "url('images/cake.jpg')";
//document.getElementById("myDiv").style.backgroundImage =     "url('images/cake.jpg')";  


let birthYear = prompt("Enter Your Birth Year");
let birthMonth = prompt("Enter Your Birth Month (As A Number)");
let birthDay = prompt("Enter Your Birth Day");
let date = new Date();
let currentYear = date.getFullYear();
let currentMonth = date.getMonth() + 1;
let currentDay = date.getDate();
let yearAge = currentYear - birthYear;
let monthAge = currentMonth - birthMonth;
let dayAge = currentDay - birthDay;
let monthPluralizer = "";
let dayPluralizer = "";

if (monthAge === 1) {
  monthPluralizer = "Month";
} else {
  monthPluralizer = "Months";
}

if (dayAge === 1) {
  dayPluralizer = "Day";
} else {
  dayPluralizer = "Days";
}

if (currentMonth < birthMonth) {
  monthAge = monthAge + 12;
  yearAge = yearAge - 1;
}

if (currentDay < birthDay) {
  monthAge = monthAge - 1;
  if (currentMonth === 1 || 3 || 5 || 7 || 8 || 10 || 12) {
    dayAge = dayAge + 31;
  } else if (currentMonth === 4 || 6 || 9 || 11) {
    dayAge = dayAge + 30;
  } else if (currentMonth === 2) {
    dayAge = dayAge + 28;
  }
}

if (currentMonth == birthMonth && currentDay < birthDay) {
  monthAge = monthAge + 12;
  yearAge = yearAge - 1;
}


document.write("<p>Your Birth Date Is " + birthMonth + "/" + birthDay + "/" + birthYear + "</p><br>");
document.write("<p>Today's Date Is " + currentMonth + "/" + currentDay + "/" + currentYear + "</p><br>");
document.write("<p>You Are " + yearAge + " Years, " + monthAge + " " + monthPluralizer + " & " + dayAge +
  " " + dayPluralizer + " Old.</p><br>");
if (birthMonth == 0 && birthDay == 0 && birthYear == 0 ) {
  document.write("<p>Hello Jesus!<p>")
} else if (birthMonth === null && birthDay === null && birthYear === null ) {
  document.write("<p>Hello Jesus!<p>")
}





</script>
</div>
</body>
</html>

年龄计算器
#myDiv{
背景图片:url('images/cake.png');
背景尺寸:封面;
}
//document.body.style.backgroundImage=“url('images/cake.jpg')”;
//document.getElementById(“myDiv”).style.backgroundImage=“url('images/cake.jpg')”;
让birthYear=提示(“输入您的出生年份”);
让birthMonth=提示(“输入您的出生月份(作为数字)”;
让生日=提示(“输入您的生日”);
让日期=新日期();
让currentYear=date.getFullYear();
让currentMonth=date.getMonth()+1;
让currentDay=date.getDate();
让yearAge=当前年份-出生年份;
让monthAge=当前月份-出生月份;
让dayAge=当前日期-生日;
让monthPluralizer=“”;
让dayPluralizer=“”;
如果(monthAge==1){
monthPluralizer=“月”;
}否则{
monthPluralizer=“月”;
}
如果(日龄===1){
dayPluralizer=“日”;
}否则{
dayPluralizer=“天”;
}
如果(当前月<出生月){
monthAge=monthAge+12;
yearAge=yearAge-1;
}
如果(当前日期<生日){
monthAge=monthAge-1;
如果(当前月份===1 | 3 | 5 | 7 | 8 | 10 | 12){
日龄=日龄+31;
}else if(当前月===4 | | 6 | | 9 | | 11){
日龄=日龄+30;
}否则如果(当前月===2){
日龄=日龄+28;
}
}
如果(当前月==生日月和当前日<生日){
monthAge=monthAge+12;
yearAge=yearAge-1;
}
文件。写上(“你的出生日期是”+生日+“/”+生日+“/”+生日+“


”); 文档。写(“今天的日期是“+currentMonth+”/“+currentDay+”/“+currentYear+”


”); 记录。写下(“你是“+yearAge+”Years,“+monthAge+”、“+monthPluralizer+”和“+dayAge+ “+dayPluralizer+”旧的。


”; if(生日月==0&&生日==0&&birthYear==0){ 文档。写(“你好,耶稣!”) }else if(birthMonth==null和birthDay==null和birthYear==null){ 文档。写(“你好,耶稣!”) }
您的图像路径不正确,应更改路径。您可以在

中查看如何定义路径图像路径不正确,您应该更改路径。您可以在

中查看如何定义路径图像路径错误

试试这个:

   #myDiv {
      background-image: url('./images/cake.png');
      background-size: cover;
    }
如果你不工作,请告诉我


您可以阅读更多关于的信息,并在这个问题中看到另一篇类似您的文章

您的图像路径错误

试试这个:

   #myDiv {
      background-image: url('./images/cake.png');
      background-size: cover;
    }
如果你不工作,请告诉我


您可以阅读更多关于的信息,并在这个问题中看到与您类似的其他帖子

因为您使用了相对url,请确保图像文件夹与调用您的代码的url相对,并且图像显示正确,可能是案例问题(例如,Cake.png而不是Cake.png…)?您只需要修复图像路径感谢Enzo,每个说路径错误的人,我在我的通用css文件中都有类似的路径,它们引用了来自同一位置的同一个图像文件夹。它们都很好用。我检查了这个案例,甚至把文件改成了png。还是打不开。在我的HTML主页上,有一个单独的js文件和css文件,我可以毫无问题地添加图像。这个网页在我的投资组合中被设计成一个js项目,全部放在一个页面上(html w样式和嵌入的脚本)。是不是有什么原因,因为我的HTML是用document.write方法编写的,所以图片不会出现?我认为这是罪魁祸首,因为您使用了相对url,请确保images文件夹与调用您代码的url相对,并且图像显示正确,可能是案例问题(例如Cake.png而不是Cake.png…)?您只需修复图像路径谢谢Enzo,所有说路径错误的人,在我的常规css文件中有类似的路径,它们引用来自同一位置的同一图像文件夹。它们都很好用。我检查了这个案例,甚至把文件改成了png。还是打不开。在我的HTML主页上,有一个单独的js文件和css文件,我可以毫无问题地添加图像。这个网页在我的投资组合中被设计成一个js项目,全部放在一个页面上(html w样式和嵌入的脚本)。是不是有什么原因,因为我的HTML是用document.write方法编写的,所以图片不会出现?我认为这是罪魁祸首