【发布时间】:2015-11-23 12:01:36
【问题描述】:
<!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....
-
啊哈,我不能那样做吗?好的,我现在要做什么?