zoukankan      html  css  js  c++  java
  • JQuery案例:购物车加减

    购物车加减

    <head>
    	<meta charset="UTF-8">
    	<title>加减购物车</title>
    	<style type="text/css">
    		input {
    			 35px;
    			height: 35px;
    			font-size: 20px;
    			text-align: center;
    		}
    	</style>
    	<script src="js/jquery-3.3.1.min.js"></script>
    	<script>
    		$(function() {
    			$("input[value='-']").click(function() {
    				var $txt = $(this).next("input");
    				var num = parseInt($txt.val());
    				if(num - 1 >= 0) {
    					$txt.val(num - 1);
    				}
    			});
    			$("input[value='+']").click(function() {
    				var $txt = $(this).prev("input");
    				var num = parseInt($txt.val());
    				$txt.val(num + 1);
    			});
    		});
    	</script>
    </head>
    
    <body>
    	<p>
    		<input type="button" value="-" />
    		<input type="text" value="1" />
    		<input type="button" value="+" />
    	</p>
    
    	<p>
    		<input type="button" value="-" />
    		<input type="text" value="1" />
    		<input type="button" value="+" />
    	</p>
    
    </body>
    
  • 相关阅读:
    ACM-ICPC ShangHai 2014
    DEBUG感想
    WireShark 使用日记
    C++ 备忘录
    BZOJ 1022 [SHOI2008]小约翰的游戏John
    高斯消元
    BZOJ3236 [Ahoi2013]作业
    BZOJ P3293&&P1045
    ZKW费用流的理解
    BZOJ 几道水题 2014-4-22
  • 原文地址:https://www.cnblogs.com/tigerlion/p/11178793.html
Copyright © 2011-2022 走看看