[英]How to save the subtracted value from span to cookie till checkbox unchecked
I have this bit of code which carries some numeric values within the span but when u click on checkbox it subtract 1 from the main value, basically it subtracts 1 from the total value, how to achieve this even if the form is submitted the deducted value in span remains same unless the checkbox is unchecked? 我有这段代码在跨度内包含一些数值,但是当您单击复选框时,它从主值中减去1,基本上从总值中减去1,即使提交表单扣除的值也如何实现跨度保持不变,除非未选中该复选框?
HTML is here with 10 for example value: HTML此处有10个示例值:
<input type="checkbox" id="featured" name="featured" <?php echo $checked;?> /> (<span id="credit">10</span>)
JS: JS:
<script>
$(function () {
$('#featured').change(function () {
var currentValue = parseInt($('#credit').text());
var newValue = currentValue + ($(this).prop('checked') ? -1 : 1);
$('#credit').text(newValue);
});
});
</script>
Your time and help would be appreciated. 您的时间和帮助将不胜感激。
<script>
$(function () {
$('#featured').change(function () {
var savedValue = localStorage.checkboxValue;
var currentValue = savedValue ? parseInt(savedValue) : parseInt($('#credit').text());
var newValue = currentValue + ($(this).prop('checked') ? -1 : 1);
$('#credit').text(newValue);
localStorage.checkboxValue = newValue;
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.