JavaScript值更改CheckBox

时间:2016-03-21 22:45:21

标签: javascript html

如果选中了复选框,我想要更改字符串的值:

<input id="checkbox-2" class="checkbox-custom" name="checkbox-group" type="checkbox">

到目前为止,我没有JavaScript解决方案,但是当我选中复选框时,我想更改为下面显示的两个值:

<h3><i class="fa fa-check"></i> <span class="the-amount"><?= $stringvalue ?></span></h3>
<h3><b>TOTAL:</b> <span>$<?= $cost ?></span></h3>

1 个答案:

答案 0 :(得分:0)

我建议使用jQuery。

&#13;
&#13;
$("#checkbox-2").change(function(){
 $(this).is(":checked") ? $("#text").html("checked") : $("#text").html("unchecked");
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="checkbox-2" class="checkbox-custom" name="checkbox-group" type="checkbox">
<div id="text">checkstatus</div>
&#13;
&#13;
&#13;