<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>moockup< /title>
<style>
.yellowBackground {
background-color: yellow;
}
.redBackground {
background-color: red;
}
</style>
</head>
<body>
<button id="button" class="yellowBackground" id="thumb" >paina tästä< /button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(function() {
$("#button").click(function() {
changeThumb();
});
});
function changeThumb() {
$("#thumb").toggleClass("yellowBackground redBackground");
}
</script>
</body>
</html>
为什么这不起作用我想按下该按钮,它必须在每次点击后将其颜色更改为黄色和红色,我知道如何使用JavaScript,但我现在正在学习jQuery。按钮更改颜色
你有你的按钮标记两个ID .... –
啊哈我不能这样做呢?好吧,我现在要做什么? – waleedd32