通过单击按钮来增加数字 [英] Increment a number by clicking onto a button

查看:67
本文介绍了通过单击按钮来增加数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上的div块中有数字$likes_number.我想知道如何通过单击按钮来动态地增加它吗?

I have the number $likes_number in a div block on my page. I would like to know how to increment it dynamically by clicking on a button?

我的代码:

<div id="likes">
    <span class="figure">
        <?php echo $likes_number ;?>
    </span>
</div>
<button type="button" id="like" >Like</button>

推荐答案

<script type="text/javascript" src="//code.jquery.com/jquery-1.6.2.js"></script>
<div id="likes">
    <span class="figure"></span>
</div>
<button type="button" id="like">Like</button>
<script type="text/javascript">
    var clicks = 0; $("#like").click(function(){ clicks++; $('.figure').html(clicks);});
</script>

实时示例: https://jsfiddle.net/nTmu7/2/

这篇关于通过单击按钮来增加数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆