使用jquery累积或删除小数

时间:2017-03-19 06:23:31

标签: javascript jquery html

如何使用jquery累积或删除小数

HTML:

<button>Run</button>

<p>
  <span class='aaa'>333</span> 
  <span class='bbb'></span>  
</p> 

jQuery:

// jquery
$(document).ready(function(){
    $("button").click(function(){
        var aaa = $(".aaa").html();
        var bbb = aaa * 12/100;
        $(".bbb").html(bbb);
    });         
});

提前谢谢

&#13;
&#13;
$(document).ready(function(){
    $("button").click(function(){
		var aaa = $(".aaa").html();
		var	bbb = aaa * 12/100;
		$(".bbb").html(bbb);
    });			
});	
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<button>Run</button>

<p>
  <span class='aaa'>333</span> 
  <span class='bbb'></span>  
</p> 
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

console.log(Math.round(39.96));
console.log(Math.round(39.40));

// jquery
$(document).ready(function(){
    $("button").click(function(){
        var aaa = $(".aaa").html();
        var bbb = Math.round(aaa * 12/100);
        $(".bbb").html(bbb);
    });         
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Run</button>

<p>
  <span class='aaa'>333</span> 
  <span class='bbb'></span>  
</p>