jQuery實現(xiàn)簡易商城系統(tǒng)項目實操
一.效果圖
二.body
<body> <table border="1" cellpadding="0" cellspacing="0"> <tr> <th><input type='checkbox' name="c1"/>全選</th> <th>商品信息</th> <th>宜美惠價</th> <th>數(shù)量</th> <th>操作</th> </tr> <tr class="tr_0"> <td> <input name="" type="checkbox" value=""/> </td> <td> <img src="images/sang.gif" class="products"/><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >天堂雨傘</a></td><td>¥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">刪除</a> </td> </tr> <tr> <td> <input name="" type="checkbox" value=""/> </td> <td> <img src="images/iphone.gif" class="products"/><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >蘋果手機iphone5</a></td><td>¥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">刪除</a> </td> </tr> </table> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="add">添加</a> </body>
三.jQuery
<script type="text/javascript" src="js/jquery-1.12.4.js" ></script> <script> $(function(){ //點擊加號觸發(fā)事件 $('[src="images/add.gif"]').click(function(){ var num=parseInt($(this).prev().val()); $(this).prev().val(num+1); }); //點擊減號觸發(fā)事件 $('[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<te.length;i++){ if(i==2 || te[i]=="."){ alert('不能超過100,不能有小數(shù)'); return $(this).val(1); }; }; if(te<=0 || isNaN(te)){ $(this).val(1); }; }); }); </script>
四.css
<style type="text/css" > *{ font-size:12px; } </style>
五.小結(jié)
本章使用jQuery的方式實現(xiàn)了一個簡易的商城系統(tǒng),這一個比較潦草,明天再實現(xiàn)一個比較好看的.
到此這篇關(guān)于jQuery實現(xiàn)簡易商城系統(tǒng)項目實操的文章就介紹到這了,更多相關(guān)jQuery商城系統(tǒng)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Jquery uploadify 多余的Get請求(404錯誤)的解決方法
下面小編就為大家?guī)硪黄狫query uploadify 多余的Get請求(404錯誤)的解決方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-01-01jQuery插入節(jié)點和移動節(jié)點用法示例(insertAfter、insertBefore方法)
這篇文章主要介紹了jQuery插入節(jié)點和移動節(jié)點的方法,結(jié)合實例形式分析了insertAfter和insertBefore方法針對頁面元素節(jié)點操作的使用技巧,需要的朋友可以參考下2016-09-09jquery+json實現(xiàn)動態(tài)商品內(nèi)容展示的方法
這篇文章主要介紹了jquery+json實現(xiàn)動態(tài)商品內(nèi)容展示的方法,涉及jQuery操作及解析json格式數(shù)據(jù)的相關(guān)技巧,需要的朋友可以參考下2016-01-01基于jQuery 實現(xiàn)bootstrapValidator下的全局驗證
這篇文章主要介紹了基于jQuery 實現(xiàn)bootstrapValidator下的全局驗證 的相關(guān)資料,需要的朋友可以參考下2015-12-12jquery.validate.js插件使用經(jīng)驗記錄
工作中使用到了jquery.validate.js插件,下面將其用法整理一下,方便以后使用2014-07-07