Javascript 在一个div中得到一个数字,然后再加上一
我用下面的代码得到一个div里面的值(数字)加一,但是如果值是1,我按下我的按钮,它给我01,我想加一,如果它是2,再按下我的按钮,它给我22 我的代码是:Javascript 在一个div中得到一个数字,然后再加上一,javascript,jquery,Javascript,Jquery,我用下面的代码得到一个div里面的值(数字)加一,但是如果值是1,我按下我的按钮,它给我01,我想加一,如果它是2,再按下我的按钮,它给我22 我的代码是: <div class="mybtn">0</div> <script> $(function() { $(".buttonDown").click(function() { var checkDown = $('.buttonDown').text(); $('.mybtn').hide("fas
<div class="mybtn">0</div>
<script>
$(function() {
$(".buttonDown").click(function()
{
var checkDown = $('.buttonDown').text();
$('.mybtn').hide("fast");
$('.mybtn').text(checkDown+1);
$('.mybtn').fadeIn("slow");
});
});
</script>
0
$(函数(){
$(“.buttonDown”)。单击(函数()
{
var checkDown=$('.buttonDown').text();
$('.mybtn').hide(“fast”);
$('.mybtn').text(检查+1);
$('.mybtn').fadeIn(“慢”);
});
});
演示:
演示:
演示:
演示:这是因为要将两个字符串添加到一起。尝试对变量使用
parseInt()
方法:
$('.mybtn').text(parseInt(checkDown, 10)+1);
为了获得最佳效果。这是因为您将两个字符串添加在一起。尝试对变量使用
parseInt()
方法:
$('.mybtn').text(parseInt(checkDown, 10)+1);
为了获得最佳效果。这是因为您将两个字符串添加在一起。尝试对变量使用
parseInt()
方法:
$('.mybtn').text(parseInt(checkDown, 10)+1);
为了获得最佳效果。这是因为您将两个字符串添加在一起。尝试对变量使用
parseInt()
方法:
$('.mybtn').text(parseInt(checkDown, 10)+1);
为了获得最佳结果。使用
+checkDown
而不是简单地checkDown
将字符串隐式转换为数字
var checkDown = $('.buttonDown').text();
$('.mybtn').text(+checkDown + 1);
使用
+checkDown
而不是简单地checkDown
将字符串隐式转换为数字
var checkDown = $('.buttonDown').text();
$('.mybtn').text(+checkDown + 1);
使用
+checkDown
而不是简单地checkDown
将字符串隐式转换为数字
var checkDown = $('.buttonDown').text();
$('.mybtn').text(+checkDown + 1);
使用
+checkDown
而不是简单地checkDown
将字符串隐式转换为数字
var checkDown = $('.buttonDown').text();
$('.mybtn').text(+checkDown + 1);
您当前所做的是告诉它将值连接到字符串,如“0”+1=string“01”中所示,而不是将其转换为整数,然后向其中添加一个
var checkDown = ParseInt($('.buttonDown').text());
$('.mybtn').text(checkDown+1);
您当前所做的是告诉它将值连接到字符串,如“0”+1=string“01”中所示,而不是将其转换为整数,然后向其中添加一个
var checkDown = ParseInt($('.buttonDown').text());
$('.mybtn').text(checkDown+1);
您当前所做的是告诉它将值连接到字符串,如“0”+1=string“01”中所示,而不是将其转换为整数,然后向其中添加一个
var checkDown = ParseInt($('.buttonDown').text());
$('.mybtn').text(checkDown+1);
您当前所做的是告诉它将值连接到字符串,如“0”+1=string“01”中所示,而不是将其转换为整数,然后向其中添加一个
var checkDown = ParseInt($('.buttonDown').text());
$('.mybtn').text(checkDown+1);
试试这个
<div class="mybtn">0</div>
<script>
$(function() {
$(".buttonDown").click(function()
{
var checkDown = parseInt($(this).text(), 10)
$(this).hide("fast").text(checkDown+1).fadeIn("slow");
});
});
</script>
0
$(函数(){
$(“.buttonDown”)。单击(函数()
{
var checkDown=parseInt($(this).text(),10)
$(this.hide(“fast”).text(checkDown+1).fadeIn(“slow”);
});
});
试试这个
<div class="mybtn">0</div>
<script>
$(function() {
$(".buttonDown").click(function()
{
var checkDown = parseInt($(this).text(), 10)
$(this).hide("fast").text(checkDown+1).fadeIn("slow");
});
});
</script>
0
$(函数(){
$(“.buttonDown”)。单击(函数()
{
var checkDown=parseInt($(this).text(),10)
$(this.hide(“fast”).text(checkDown+1).fadeIn(“slow”);
});
});
试试这个
<div class="mybtn">0</div>
<script>
$(function() {
$(".buttonDown").click(function()
{
var checkDown = parseInt($(this).text(), 10)
$(this).hide("fast").text(checkDown+1).fadeIn("slow");
});
});
</script>
0
$(函数(){
$(“.buttonDown”)。单击(函数()
{
var checkDown=parseInt($(this).text(),10)
$(this.hide(“fast”).text(checkDown+1).fadeIn(“slow”);
});
});
试试这个
<div class="mybtn">0</div>
<script>
$(function() {
$(".buttonDown").click(function()
{
var checkDown = parseInt($(this).text(), 10)
$(this).hide("fast").text(checkDown+1).fadeIn("slow");
});
});
</script>
0
$(函数(){
$(“.buttonDown”)。单击(函数()
{
var checkDown=parseInt($(this).text(),10)
$(this.hide(“fast”).text(checkDown+1).fadeIn(“slow”);
});
});
10指的是parseInt函数的基数或基数。在这种情况下,@Arun指定的是基数10,10
指的是parseInt函数的基数。在这种情况下,@Arun指定的是基数10,10
指的是parseInt函数的基数。在这种情况下,@Arun指定的是基数10,10
指的是parseInt函数的基数。在本例中,@Arun指定基数为10