我有一个简单的页面,有四张卡片(Div),每个卡片都有一个按钮。我写了一些jQuery的希望,当我点击按钮,我可以更改类的按钮文本& ...并切换两种状态,我继续点击它们。点击jquery更改按钮
我的下面的代码似乎适用于第一个按钮完美...但没有任何其他人。
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#un_btn").click(function() {
if ($(this).attr('class') == 'btn_s') {
$(this).html('Undo?');
$(this).removeClass('btn_s');
$(this).addClass('notsu');
} else {
$(this).html('Mark as not suitable?');
$(this).removeClass('notsu');
$(this).addClass('btn_s');
}
});
});
</script>
</head>
<body>
<div class="card">
<p>Card 1</p>
<button class="btn_s" id="un_btn">Mark as not suitable?</button>
</div>
<div class="card">
<p>Card 2</p>
<button class="btn_s" id="un_btn">Mark as not suitable?</button>
</div>
<div class="card">
<p>Card 3</p>
<button class="btn_s" id="un_btn">Mark as not suitable?</button>
</div>
<div class="card">
<p>Card 4</p>
<button class="btn_s" id="un_btn">Mark as not suitable?</button>
</div>
</body>
</html>
我在做什么错?我怎样才能得到开关在每个相应的div(卡)内的每个按钮上工作?