jquery实现数字加减

HTML
<input type="button" value="-" class="jian">
<span class="num"><?=$list['g_num']?></span>
<input type="button" value="+" class="add">
JQUERY

<script>
    //加的效果
$(".add").click(function(){
    var n=$(this).prev().html();
    var num=parseInt(n)+1;
    if(num==0){ return;}
    $(this).prev().html(num);
});
//减的效果
$(".jian").click(function(){
    var n=$(this).next().html();
    var num=parseInt(n)-1;
    if(num==0){ return}
    $(this).next().html(num);
});
</script>

posted @ 2017-03-03 10:26  先生丨孙  阅读(21915)  评论(0编辑  收藏  举报