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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM