javascript development of shopping cart addition and subtraction effects
Developing addition and subtraction effects
htmlPart of the code:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>购物车加减</title> <style type="text/css"> a{ text-decoration: none;display:block;width:30px;height:30px; background:#eee;line-height:30px;font-weight:bolder; } .body{width:500px;height:300px;background:#ccc;margin:0 auto;text-align:center;padding:80px;} #a1{float:left;margin-right:20px;margin-top:2px;text-align:center;} form{float:left;} form input{width:40px;height:30px;border:1px solid #eee;text-align:center;} #a2{float:left;margin-left:20px;margin-top:2px;text-align:center;} </style> </head> <body> <div> <a href="#" id="a1">-</a> <form> <input type= "text" value="1" id='id'> </form> <a href="#" id="a2">+</a> </div> </body> </html>
First we need to get the value of the input in the form, which is 1
var input = document.getElementById ('id').value;
Stored in a variable
When the minus sign is clicked, the code is as follows:
document.getElementById('a1').onclick = function(){
}else{ getElementById('id').value>1){
. }else{
Document.getelementbyid ('ID'). Value = 1;
}
}
}
## When clicking the plus number, the code is as follows:
:
document.getElementById('a2').onclick = function(){
alert("Please enter a number");
v1=parseInt(v1);
through v1=parseInt(v1); ;
# var id = document.getElementById('id').value; document.getElementById ('ID'). Value = 1;
Return false;
}
}
(
This way we realize shopping The effect of adding and subtracting car numbers