Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.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
Jquery 一个css中for循环生成的页面的不同背景_Jquery_Html_Css - Fatal编程技术网

Jquery 一个css中for循环生成的页面的不同背景

Jquery 一个css中for循环生成的页面的不同背景,jquery,html,css,Jquery,Html,Css,对于每个页面,我都需要使用不同的背景图像,其ID由以下for循环语句生成: `$`function nextButton() { if(curNum<numScreens) { curNum = parseInt(curNum)+1; document.location.href = '#'+curNum; $( init ); } } 但它不起作用。 你能帮帮我吗 只需将body.1、body.2和body.3分别更改为: body #

对于每个页面,我都需要使用不同的背景图像,其ID由以下for循环语句生成:

`$`function nextButton() {
    if(curNum<numScreens) {
      curNum = parseInt(curNum)+1;
      document.location.href = '#'+curNum;
      $( init );
   }
}
但它不起作用。
你能帮帮我吗

只需将body.1、body.2和body.3分别更改为:

body #body_1 {...}
body #body_2 {...}
body #body_3 {...}

这可能是一个输入错误,但在html中,主体有一个
id
,在css中,您通过
class
选择器)访问它。此外,类和id不能以数字开头。试着用“#body-1”或其他什么来引导。我确认@Torr3nt是正确的,不能用数字引导类或ID。
body.1 { background-image: url("bg.gif"); 
background-repeat: no-repeat;
background-attachment: scroll;
background-position: 53% 10%;
z-index: 1;
}
body.2 { background-image: url("bg1.gif"); 
background-repeat: no-repeat;
background-attachment: scroll;
background-position: 53% 10%;
z-index: 1;}

body.3 { background-image: url("bg2.gif"); 
background-repeat: no-repeat;
background-attachment: scroll;
background-position: 53% 10%;
z-index:1 }
body #body_1 {...}
body #body_2 {...}
body #body_3 {...}