1.html
<p id= "Input_main" >
<em><i id= "Pricenum" >10</i> yuan </em>
<span id= "C_sub" >-</span>
<input type= "" Name= "" maxlength= "4" id= "Numinput" value= "1"/>
<span id= "C_add" >+</span>
<span id= "Num_mun" >0</span>
</p>
2.css
*{
padding:0;
margin:0 Auto;
}
p{
width:300px;
height:200px;
margin:200px Auto;
Border:solid 1px #ccc;
Text-align:center;
padding-top:100px;
}
span{
width:30px;
line-height:30px;
height:30px;
Border:solid 1px #ccc;
Display:inline-block;
Text-align:center;
font-size:20px;
Cursor:pointer;
}
input{
height:30px;
line-height:30px;
width:50px;
padding:0;
margin:0;
}
3.js
<script src= "Http://libs.baidu.com/jquery/1.11.1/jquery.min.js" ></script>
<script type= "Text/javascript" >
$ (function () {
var TOOLFN = {
Fmoney:function (s, N) {
n = n > 0 && n < 20? N:2;
s = parsefloat ((S + "). Replace (/[^\d\.-]/g, ')"). ToFixed (n) + ';
var L = s.split ('. ') [0].split ('). Reverse (),
r = S.split ('. ') [1],
t = ';
for (var i = 0; i < l.length; i++) {
T + = L[i] + ((i + 1)% 3 = = 0 && (i + 1)! = L.length? ‘,‘ : ‘‘);
}
Return T.split ("). Reverse (). Join (') + '. ' + R;
}
};
var eId;
var curinput;
var isint=/^[0-9]*[1-9][0-9]*$/;
var regexpint= new RegExp (Isint);
var pricenum = $ (' #priceNum '). Text ();
$ (' #input_main '). On (' click ', ' span ', function (e) {
Eid= e.target.id;
Curinput =document.getelementbyid (' numinput ');
if (eId = = ' c_sub ' && curinput.value > 1) {
--curinput.value;
}else if (eId = = ' C_add ' && curinput.value < 9999) {
++curinput.value;
}
$ (' #num_mun '). Text (Toolfn.fmoney (Pricenum * curinput.value, 2));
}). On (' KeyUp ', ' #numInput ', function () {
Curinput = document.getElementById (' numinput ');
if (CurInput.value.match (regexpint) = = null) {
Curinput.value = 1;
}
$ (' #num_mun '). Text (Toolfn.fmoney (Pricenum * curinput.value, 2));
})
})
</script>
Input calculation quantity and amount