網站首頁 編程語言 正文
一.效果圖
二.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"/><a href="#" >天堂雨傘</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="#" class="del">刪除</a>
</td>
</tr>
<tr>
<td>
<input name="" type="checkbox" value=""/>
</td>
<td>
<img src="images/iphone.gif" class="products"/><a href="#" >蘋果手機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="#" class="del">刪除</a>
</td>
</tr>
</table>
<a href="#" class="add">添加</a>
</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<te.length;i++){
if(i==2 || te[i]=="."){
alert('不能超過100,不能有小數');
return $(this).val(1);
};
};
if(te<=0 || isNaN(te)){
$(this).val(1);
};
});
});
</script>
四.css
<style type="text/css" >
*{
font-size:12px;
}
</style>
五.小結
本章使用jQuery的方式實現了一個簡易的商城系統,這一個比較潦草,明天再實現一個比較好看的.
原文鏈接:https://blog.csdn.net/weixin_45539338/article/details/125434802
相關推薦
- 2022-09-27 Swift超詳細講解指針_Swift
- 2024-07-18 【探索SpringCloud】服務發現-Nacos服務端數據結構和模型
- 2023-07-13 替換字符串中的任意字符及正則隱藏手機號中間四位
- 2022-03-21 C語言楊輝三角兩種實現方法_C 語言
- 2022-06-02 C語言的模板與泛型編程你了解嗎_C 語言
- 2022-06-01 C#類型轉換之自定義隱式轉換和顯式轉換_C#教程
- 2022-05-22 C#中深拷貝和淺拷貝的介紹與用法_C#教程
- 2024-01-16 關于jquery中的ajax 網絡異常失敗回調函數
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支