jQuery實現簡易商城系統專案實操詳解
導讀 | 這篇文章主要介紹了jQuery實現簡易商城系統專案實操,文章圍繞主題展開詳細的內容介紹,具有一定的參考價值,感興趣的小夥伴可以參考一下 |
一.效果圖
二.body
< body> < table border="1" cellpadding="0" cellspacing="0"> < tr> < th>< input type='checkbox' name="c1"/>全選< /th> < th>商品資訊< /th> < th>宜美惠價< /th> < th>數量< /th> < th>操作< /th> < /tr> < tr class="tr_0"> < td> < input name="" type="checkbox" value=""/> < /td> < td> < img src="images/sang.gif" class="products"/>天堂雨傘¥32.9元 < /td> < td> < img src="images/subtraction.gif" width="20" height="20"/> < input type="text" class="quantity" value="1"/> < img src="images/add.gif" width="20" height="20"/> < /td> < td> < a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="del">刪除 < /td> < /tr> < tr> < td> < input name="" type="checkbox" value=""/> < /td> < td> < img src="images/iphone.gif" class="products"/>蘋果手機iphone5¥3339元 < /td> < td> < img src="images/subtraction.gif" width="20" height="20"/> < input type="text" class="quantity" value="1"/> < img src="images/add.gif" width="20" height="20"/> < /td> < td> < a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="del">刪除 < /td> < /tr> < /table> < a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="add">新增 < /body>
三.jQuery
< script type="text/javascript" src="js/jquery-1.12.4.js" >< /script> < script> $(function(){ //點選加號觸發事件 $('[src="images/add.gif"]').click(function(){ var num=parseInt($(this).prev().val()); $(this).prev().val(num+1); }); //點選減號觸發事件 $('[src="images/subtraction.gif"]').click(function(){ var num=parseInt($(this).next().val()); if(num<=0){ return alert('不能再少了!'); }; $(this).next().val(num-1); }); //刪除事件 $('[class="del"]').click(function(){ $(this).parent().parent().remove(); }); //選中框,全選框事件 $('[type="checkbox"]').click(function(){ var len=$('[type="checkbox"]').length; var clen=$('[type="checkbox"]:checked').length; var t1=$('[name="c1"]').prop("checked"); var pd=$(this).parent().text(); if(pd=="全選"){ $('[name="c1"]').prop("checked",t1); $('[type="checkbox"]').prop("checked",t1); return ""; } if(clen==len-1 & t1==false){ $('[name="c1"]').prop("checked",true); }else if(clen>=len-1 & t1==true){ $('[name="c1"]').prop("checked",false); } }); //新增事件 $('[class="add"]').click(function(){ var newD=$('tr:eq(2)').clone(); $('tr:last').after(newD); }); //輸入框 $('[type="text"]').change(function(){ var te=$(this).val(); te=te.toString(); for(i=0;i<1te.length;i++){ if(i="=2" ||="" te[i]="="."){" alert('不能超過100,不能有小數');="" return="" $(this).val(1);="" };="" if(te<1="0" isnan(te)){="" });=""
四.css
< style type="text/css" > *{ font-size:12px; } < /style>
本章使用jQuery的方式實現了一個簡易的商城系統,這一個比較潦草,明天再實現一個比較好看的.
到此這篇關於jQuery實現簡易商城系統專案實操的文章就介紹到這了
原文來自:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69955379/viewspace-2906101/,如需轉載,請註明出處,否則將追究法律責任。