<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../css/reset.css">
<style>
.lt-box {
width: 800px;
margin: 0 auto;
}
img {
width: 59px;
float: left;
}
tbody span {
float: left;
width: 140px;
margin-left: 8px;
}
tbody p {
float: left;
margin-left: 20px;
}
b {
display: block;
color: #a5a5a5;
font-weight: 400;
}
tbody button {
width: 14px;
height: 19px;
outline: none;
float: left;
}
tbody input[type='text'] {
width: 31px;
height: 15px;
outline: none;
float: left;
text-align: center;
}
a {
color: #000;
}
.lt-name {
width: 500px !important;
text-align: left;
}
td {
/* text-align: center; */
width: 100px;
height: 92px;
}
.lt-shangpin {
float: right;
}
.lt-shangpin p {
float: left;
}
.lt-shangpin span {
color: #ff1300;
}
.lt-je {
color: #ff1300;
}
u {
float: left;
}
s {
float: left;
text-decoration: none;
}
table {
border-collapse: collapse;
}
table td {
border-bottom: 1px solid #dedede;
}
</style>
</head>
<script src="../js/jquer-3.6.0.js"></script>
<body>
<div class="lt-box">
<table>
<thead>
<tr>
<td><input type="checkbox" name="" id="lt_qx">全選</td>
<td>商品信息</td>
<td>單價(jià)</td>
<td>數(shù)量</td>
<td>金額</td>
<td>操作</td>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" class="dx"></td>
<td class="lt-name">
<span>韓版中長(zhǎng)款純色休閑青年風(fēng)衣英倫秋冬男毛尼材料寬松外套時(shí)尚大衣</span>
<p>
<b>顏色:卡其色有紐扣</b>
<b>尺碼:L</b>
</p>
</td>
<td><s>¥</s><u>208.00</u></td>
<td>
<button>-</button>
<input type="text" value="1">
<button>+</button>
</td>
<td class="lt-je"><s>¥</s><u>208.00</u></td>
<td><a href="javascript:;" onclick="del(this)">刪除</a></td>
</tr>
<tr>
<td><input type="checkbox" class="dx"></td>
<td class="lt-name">
<span>李寧2016新款男子籃球鞋音速3高幫反彈籃球場(chǎng)地鞋</span>
<p>
<b>顏色:黃光果粉</b>
<b>鞋碼:42</b>
</p>
</td>
<td><s>¥</s><u>339.00</u></td>
<td>
<button>-</button>
<input type="text" value="1">
<button>+</button>
</td>
<td class="lt-je"><s>¥</s><u>339.00</u></td>
<td><a href="javascript:;" onclick="del(this)">刪除</a></td>
</tr>
<tr>
<td><input type="checkbox" class="dx"></td>
<td class="lt-name">
<span>adidas 阿迪達(dá)斯籃球 男子籃球鞋 Regulate</span>
<p>
<b>顏色:銀金</b>
<b>鞋碼:43.5</b>
</p>
</td>
<td><s>¥</s><u>419.00</u></td>
<td>
<button>-</button>
<input type="text" value="1">
<button>+</button>
</td>
<td class="lt-je"><s>¥</s><u>419.00</u></td>
<td><a href="javascript:;" onclick="del(this)">刪除</a></td>
</tr>
<tr>
<td><input type="checkbox" class="dx"></td>
<td class="lt-name">
<span>耐克歐文六 籃球運(yùn)動(dòng)鞋</span>
<p>
<b>顏色:全明星配色</b>
<b>鞋碼:41.5</b>
</p>
</td>
<td><s>¥</s><u>949.00</u></td>
<td>
<button>-</button>
<input type="text" value="1">
<button>+</button>
</td>
<td class="lt-je"><s>¥</s><u>949.00</u></td>
<td><a href="javascript:;" onclick="del(this)">刪除</a></td>
</tr>
</tbody>
</table>
<div class="lt-shangpin">
<p>已選商品<span id="lt_xz">0</span>件商品</p>
<p style="margin-left: 10px;">合計(jì)(不含運(yùn)費(fèi))<span id="lt_jg">¥0.00</span></p>
</div>
</div>
</body>
</html>
<script>
// ++
$('button:contains(+)').click(function () {
var inpV = parseInt($(this).prev().val())
inpV++
parseInt($(this).prev().val(inpV))
je($(this), $(this).parent().find('input').val())
zj()
})
// --
$('button:contains(-)').click(function () {
var inpV = parseInt($(this).next().val())
inpV--
if (inpV <= 1) {
inpV = 1
}
parseInt($(this).next().val(inpV))
je($(this), $(this).parent().find('input').val())
zj()
})
// 刪除
$('a').click(function () {
$(this).parent().parent().remove()
geshu()
// 總價(jià)格
zj()
// 單跟全
fx()
})
// 金額
function je(but, n) {
but.parent().next().find('u').text(parseInt(but.parent().prev().find('u').text() * n) + '0.00')
}
// 單選添加點(diǎn)擊事件
// 獲取總價(jià)格
function zj() {
var num = 0
var ele = $('.dx:checked')
for (var i = 0; i < ele.length; i++) {
num += Number($(ele[i]).parent().parent().find('.lt-je u').text())
}
$('#lt_jg').text('¥' + num)
}
// 點(diǎn)擊全選
$('#lt_qx').click(function () {
console.log($(this).is(':checked'))
if ($(this).is(':checked')) {
$('.dx').prop('checked', true)
} else {
$('.dx').prop('checked', false)
}
fx()
geshu()
})
// 商品個(gè)數(shù)
$('.dx').click(function () {
// 個(gè)數(shù)
geshu()
// 總價(jià)格
zj()
// 單跟全
fx()
})
// 個(gè)數(shù)
function geshu() {
var num = 0
$('.dx').each(function (i, e) {
if($(e).is(':checked') == true){
num++
}
})
$('#lt_xz').text(num)
}
// 單跟全
function fx() {
var bool = true
$('.dx').each(function (i, e) {
console.log($(e).is(':checked'))
if ($(e).is(':checked') == false) {
bool = false
}
$('#lt_qx').prop('checked', bool)
})
}
</script>
jQuery實(shí)現(xiàn)購(gòu)物車(chē)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門(mén)肖粮,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)孤页,“玉大人,你說(shuō)我怎么就攤上這事涩馆⌒惺” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵魂那,是天一觀的道長(zhǎng)悲龟。 經(jīng)常有香客問(wèn)我,道長(zhǎng)冰寻,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任皿渗,我火速辦了婚禮斩芭,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘乐疆。我一直安慰自己划乖,他們只是感情好,可當(dāng)我...
- 文/花漫 我一把揭開(kāi)白布挤土。 她就那樣靜靜地躺著琴庵,像睡著了一般。 火紅的嫁衣襯著肌膚如雪仰美。 梳的紋絲不亂的頭發(fā)上迷殿,一...
- 那天,我揣著相機(jī)與錄音咖杂,去河邊找鬼庆寺。 笑死,一個(gè)胖子當(dāng)著我的面吹牛诉字,可吹牛的內(nèi)容都是我干的懦尝。 我是一名探鬼主播知纷,決...
- 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼陵霉!你這毒婦竟也來(lái)了琅轧?” 一聲冷哼從身側(cè)響起,我...
- 序言:老撾萬(wàn)榮一對(duì)情侶失蹤踊挠,失蹤者是張志新(化名)和其女友劉穎乍桂,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體止毕,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡模蜡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了扁凛。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片忍疾。...
- 正文 年R本政府宣布则披,位于F島的核電站洗出,受9級(jí)特大地震影響士复,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜翩活,卻給世界環(huán)境...
- 文/蒙蒙 一阱洪、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧菠镇,春花似錦冗荸、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至隘梨,卻和暖如春程癌,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背轴猎。 一陣腳步聲響...
- 正文 我出身青樓烦秩,卻偏偏與公主長(zhǎng)得像垮斯,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子只祠,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 需求分析: 列表頁(yè)list.html html結(jié)構(gòu) 列表頁(yè)功能一: 初始化展示商品列表 前端代碼 后端代碼 列...
- 做的一個(gè)關(guān)于購(gòu)物車(chē)的小案例兜蠕,用表格實(shí)現(xiàn),歡迎指正抛寝! 功能包括以下幾點(diǎn): 1熊杨、商品全選、全不選 2盗舰、選擇刪除商品 3...
- 效果圖: html: css樣式: js:
- 需求分析: 列表頁(yè)list.html html結(jié)構(gòu) 列表頁(yè)功能一: 初始化展示商品列表 前端代碼 后端代碼 列...