Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery递增/递减价格复选框_Javascript_Jquery_Html - Fatal编程技术网

Javascript Jquery递增/递减价格复选框

Javascript Jquery递增/递减价格复选框,javascript,jquery,html,Javascript,Jquery,Html,这是我的代码我不奇怪为什么这不起作用 <script type="text/javascript" > var increment2=0; $('.checkbox').live('change', function() { $('.number').html( '(' + (increment2 += this.checked ? 1 : -1) + ')'); }) </script> <td><input typ

这是我的代码我不奇怪为什么这不起作用

<script type="text/javascript" >
var increment2=0;
$('.checkbox').live('change', function() {
    $('.number').html( '(' + (increment2 += this.checked ? 1 : -1) + ')');             
})
</script> 
<td><input type="checkbox" class="checkbox" name="cb" value="1"> 1 </td>
<div class="number">
hello
</div>

从jQuery1.7开始,
live
方法是

如果您使用的是较新版本,则应在上使用
。并确保指定要执行的事件处理


因此,当我使用非常旧版本的jQuery时,您的代码运行良好

var increment2=0;
$('.checkbox').live('change',function()){
$('.number').html('('+(increment2+=this.checked?1:-1)+');
})

1.
你好

您使用的jQuery的哪个过时版本仍然有效?live早就被弃用并从jQuery中删除。控制台中是否有错误?无。即使这个代码也不起作用。。。是否有人有想法var increment2=0$('.checkbox').live('.click',function(){if($(this).attr('checked')=='checked'){increment2+=10;}else{increment2-=10;}$('.number').html('(hello'+increment2+'));})那么您使用的是什么过时的jQuery版本呢。我在1.3中使用了它,并运行了您的原始代码。正如我在上一篇评论中告诉您的,从jQuery1.7开始,
live
方法已被弃用。在
上使用
var increment2=0; 
        $('.checkbox').live('click', function() { 
            if ($(this).attr('checked') === 'checked') {
                increment2+=10;                 
            } else {
                increment2-=10;
            }
            $('.number').html( '( hello ' + increment2 + ')');             
    })
var increment2=0;
$(function() { // $.ready
    $('.checkbox').on('change', function() {
        $('.number').html( '(' + (increment2 += this.checked ? 1 : -1) + ')');
    });
});