gpt4 book ai didi

JQuery - 单击按钮更改页面背景颜色

转载 作者:行者123 更新时间:2023-11-28 08:36:55 25 4
gpt4 key购买 nike

我是 jquery 的新手,我正在尝试在单击按钮后更改页面背景颜色。

我已经搜索过并且有很多关于类似事情的问题,但我正在寻找专门针对页面背景颜色更改的答案。

如果有任何帮助,我将不胜感激,谢谢,Freddie

HTML:

<!DOCTYPE HTML>
<html lang="en">

<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>

<body>
<section class="text">
CLICK THE BUTTON TO<br> CHANGE THE BACKGROUND!
</section>

<button id="btn">CLICK ME!</button>

</body>
</html>

CSS:

body {
height: ;
background: #D8D8D8;
}

.text {
color: #686868;
font-family: arial;
font-size: 2em;
text-align: center;
margin-top: 50px;
margin-bottom: 20px;
}

#btn {
margin-left: 550px;
width: 200px;
height: 100px;
font-size: 2em;
border-radius: 10px;
background: #ffffff;
}

#btn:hover {
background: #ff0000;
color: #ffffff;
}

JS:

$(button).click(function() {
$(this).css('background', '#ff0000');
)};

最佳答案

$( "#change_background" ).on( "click", function() {
$("body").css("background-color","#000000");
});

Here你有一个例子。

关于JQuery - 单击按钮更改页面背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21687489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com