我有p元素遍歷,每個選中的輸入影響未選中輸入
<div id="wrapper">
<p><input name="product" type="checkbox"> Unchecked </p>
<p><input name="product" type="checkbox"> Unchecked </p>
<p><input name="product" type="checkbox"> Unchecked </p>
<p><input name="product" type="checkbox"> Unchecked </p>
<p><input name="product" type="checkbox"> Unchecked </p>
<input type="submit" value="submit" id="submit">
</div>
但是如果我檢查了3複選框,例如它會影響第一和第二
$('#submit').on('click', function() {
$('#wrapper p').each(function() {
if ($('input[type=checkbox]').is(':checked')){
$(this).text($(this).text().replace("Unchecked", "Checked"));
}
});
});
內的複選框列表
我認爲這是因爲它發現一個被檢查過的所有先前的複選標記,但我不知道如何解決這個問題。
小提琴:http://jsfiddle.net/pt9w8ksf/1/