標籤:style blog http java color os
<?phpsession_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><head> <title>jQuery實現購物車多物品數量的加減+總價+刪除計算</title> <script type="text/javascript" src="jquery-1.8.3.min.js"></script> <script> $(function(){ var _url = $(‘#siteurl‘).val(); $(‘.delete‘).click(function(){ var t=$(this).parent(‘td‘).parent(‘tr‘); var tt=$(this).parent(‘td‘).find(‘input[class*=text_box]‘); tt.val(0); setTotal(); t.hide(); }); $(".add").click(function(){ var t=$(this).parent(‘td‘).find(‘input[class*=text_box]‘); t.val(parseInt(t.val())+1); setTotal(); }); $(".min").click(function(){ var t=$(this).parent(‘td‘).find(‘input[class*=text_box]‘); t.val(parseInt(t.val())-1) if(parseInt(t.val())<1){ t.val(1); } setTotal(); }); $(‘.text_box‘).keyup(function(){ setTotal(); }); function setTotal(){ var s=0; $("#tab td").each(function(){ var numbers = parseInt($(this).find(‘input[class*=text_box]‘).val()); if($.isNumeric(numbers)) { numbers = parseInt(numbers); }else { numbers = 1; } $(this).find(‘input[class*=text_box]‘).val(numbers); s += numbers*parseFloat($(this).find(‘span[class*=price]‘).text()); // bof 用ajax在_url中刪除指定的購物車中$_SESSION相關資訊 var pid =$(this).find(‘input[class*=product_id]‘); $.ajax({ url:_url, type: ‘post‘, data:{proid : pid.val()}, success: function(data){ // 回應 } }); // end }); $("#total").html(s.toFixed(2)); } // setTotal(); }); </script> </head> <body> <form action="./myform.php" method="post"><input type="hidden" name="siteUrl" id="siteurl" value="siteUrl.php" /><table id="tab"> <tr> <td> <span>單價:</span><span class="price">1.50</span> <input class="product_id" type="hidden" name="product_id" value="value" /><input class="min" name="" type="button" value="-" /> <input class="text_box" name="name2" type="text" value="1" /> <input class="add" name="" type="button" value="+" /> <a href="javascript:void(0);" class="delete">刪除</a></td> </tr> <tr> <td> <span>單價:</span><span class="price">3.95</span> <input class="min" name="" type="button" value="-" /> <input class="text_box" name="name1" type="text" value="1" /> <input class="add" name="" type="button" value="+" /> <a href="javascript:void(0);" class="delete">刪除</a></td> </tr> </table> <input type="submit" name="submit" value="submit" /></form> 總價:<label id="total"></label> <div id="product_id_value"><?php print_r($_SESSION); ?></div></body> </html>