【发布时间】:2014-03-22 03:38:33
【问题描述】:
我想在点击链接时更改页面的正文、标题、菜单和主要块的背景图像。首先,我正在尝试仅更改身体背景。我的默认正文背景图像在我的 CSS 文件中分配:
html, body {
height:1100px;
}
body {
width: 100%;
background-repeat: no-repeat;
background-size: auto 1150px;
background-image: url(../Unnamed%20Site%202/ff%20copy7.jpg);
}
我试过这个 jQuery 函数,但它不起作用。
<!DOCTYPE html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Untitled Document</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="Your name" />
<link rel="shortcut icon" href="../favicon.ico">
<link href="main.css" rel="stylesheet" type="text/css">
<link href='http://fonts.googleapis.com/css?family=Electrolize'rel='stylesheet' type='text/css' />
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.2.min.js"></script>
</head>
<body>
<div class="main">
<div id="home">
<div class="menu">
<script src="jquery.js"></script>
<script>
$("#home").click(function() {
$("body").css("backgroundImage", "url(sandpaper.png)");
});
</script>
...Some text into main (box)...
</div>
</div>
...
【问题讨论】:
-
$("body").css("background-image", "url(sandpaper.png)"); -
@Morpheus :随意把它作为答案,因为它是一个答案
-
我的错,谢谢,但不能解决问题
-
@Morpheus That doesn't matter to jQuery.
-
你看过你自己发的文章了吗?
标签: javascript jquery html css background