當前位置:首頁 » 購物大全 » 購物車復選框div怎麼做

購物車復選框div怎麼做

發布時間: 2021-02-18 21:34:50

① JS/Jquery復選框控制多個對應div的顯隱要如何實現

<!doctype html><html>
<head>
<meta charset="utf-8">
<title>無標題文檔</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.2.min.js
"></script>
</head>
<body>
<div id="dd1">淘寶</div>
<div id="dd2">新浪</div>
<div id="dd3">網易</div>
<div id="dd4">天貓</div>
</div>
<input type="checkbox" checked="checked" value="dd1" />淘寶<br />
<input type="checkbox" checked="checked" value="dd2" />新浪<br />
<input type="checkbox" checked="checked" value="dd3" />網易<br />
<input type="checkbox" checked="checked" value="dd4" />天貓<br />
<script type="text/javascript">
$(":checkbox").each(function () {
$(this).click(function () {
if ($(this).attr("checked") == "checked") {
$("#" + $(this).val()).hide();
$(this).attr("checked",false);
} else {
$("#" + $(this).val()).show();
$(this).attr("checked",true);
}
});
});
</script>
</body>
</html>

② html將一個div中已選擇的checkbox通過jquery添加到另一個div中

js
===========================================================
<scriptlanguage="javascript"src="script/jquery-1.7.1.min.js"></script>
<script>
functiongogogo(ob){
$('#div2').append('<p>'+ob+'</p>');
}
</script>
html
==============================================================
<divid="div1">
<p>
<inputtype="checkbox"value="西瓜"id="select"onChange="gogogo(this.value);">
西瓜
<inputtype="checkbox"value="香蕉"id="select2"onChange="gogogo(this.value);">
香蕉
<inputtype="checkbox"value="蘋果"id="select3"onChange="gogogo(this.value);">
蘋果
<inputtype="checkbox"value="葡萄"id="select4"onChange="gogogo(this.value);">
葡萄</p>
</div>
<divid="div2">
</div>

③ 想做一個簡單的購物車界面,非常簡單就行有代碼!用div+css做就可以

購物車外是可以的 但是核心最好還是用程序本來的核心如果自己寫,很有單獨

④ 如何通過js實現勾選復選框

js勾選復選框示例i:

//獲取頁面所有checkbox(checkbox的name設置一致)
varitems=document.getElementByName("checkbox的name");
//遍歷checkbox
for(vari=0;i<items.length;i++){
//當前回checkbox實現答勾選
items[i].checked=true;
}

⑤ angular js 帶復選框購物車怎麼寫

前段時間研究過這個,並且寫了一個購物車的小例子,今天一個偶然的機會提起,可惜忘了差不多了,糊里糊塗的也沒說清楚。翻出來,提醒下自己,保持一顆學習的心,順便再復習一遍。
先上一個最終的效果圖

構圖比較簡單,主要功能:
1. 點擊購買的時候 進行數量的增加或者條目的增加,同時總價格變化;
2. 進行刪除的時候,刪除當前條目,總價變化;
3. 進行數目增加減少的時候,總價格變化;
好,下面說代碼,抓耳撓腮的想想,有點久遠印象不太深刻了;
關於angular的基本用法,這里就不嘮叨了,網上好多的教程;
首先是商品列表,這里自己隨意列舉了一些

<script>
var items = [{
id : '1',
name : '蜂蜜',
price : 30.00
},{
id : '2',
name : '黃豆醬',
price : 15.8
},
{
id : '3',
name : '護手霜',
price : 15.00
},
{
id : '4',
name : '保溫杯',
price : 29.9
},
{
id : '5',
name : '滑鼠',
price : 39.9
},{
id : '6',
name : '米老頭',
price : 8.8
}];
//購物車中的數據;
var boughtList = {};
</script>

主要的html代碼,重新注釋下也讓自己再熟悉一遍

<div class="wrap" ng-controller="showItem"><!-- ng-controller ng的語法 -->
<h5>商品列表</h5>
<div class="left itembox border" >
<ul>
<li class="left" ng-repeat="value in items" item-id={{value.id}}>
<p>{{value.name}}</p>
<p> {{value.price}}</p>
<p>
<a href="javascript:void(0);" ng-click="buyAction($event);"
name={{value.name}} price={{value.price}} item-id={{value.id}} >購買</a>
<!-- dom 事件時的$event 就相當於普通dom事件中的window.event 對象-->
</p>
</li>
</ul>
</div>

<!-- 購物車中的數據 -->
<div class="boughtlist border">
<ul>
<li ng-repeat="value in boughtList" item-id={{value.id}}>
<span>{{value.name}}</span>
<span>{{value.price}}</span>
<span style="width:100px;" item-id={{value.id}}>
<a href="javascript:void(0);" ng-click="value.num=value.num+1;changeNum($event,value.num);" >+</a>
<input class="border" type="number" min=0 ng-model="value.num" ng-init="value.num=1" ng-change="changeNum(value.id,value.num);"/>
<!-- 這里的ng-change 是值發生變化時觸發的事件,其實這里我原先想處理成 一個自動的mvc過程,無果,只好加事件了-->
<a href="javascript:void(0);" ng-click="value.num=value.num-1;changeNum($event,value.num);">-</a>
</span>
<a href="javascript:void(0);" item-id={{value.id}} ng-click="delItem($event);" >刪除</a>
</li>
</ul>
<p ng-init=0 >總價格:{{ total | number:1}}</p>
<!-- angular的優勢體現,number:1也就是number數據,小數點後一位。-->
</div>

我記得,當時覺得比較麻煩的是 input沒有ng-blur事件;
看下js代碼

var ng = angular;
var myapp = ng.mole('myapp',[]);

var common = {
getTotal : function(total){ //每次重新清零 算出總價,這樣的話為什麼還要傳total參數?當時怎麼想的?
total = 0;
for(var k in boughtList){
if(boughtList[k]){
if(boughtList[k].num <=0){
boughtList[k].num = 0;
}
total += boughtList[k].num*boughtList[k].price;
}
}
return total;
}
}

myapp.controller('showItem',function($scope){
$scope.items = items;
$scope.boughtList = boughtList;
$scope.total = 0;
for(var k in boughtList){
if(boughtList[k]){
$scope.total += boughtList[k].num*boughtList[k].price;
}
}
$scope.buyAction = function($event){
var el = $event.target;
var id = el.getAttribute('item-id');
if(boughtList[id]){
boughtList[id].num += 1;
}else{
var arr = [];
arr.name = el.getAttribute('name');
arr.price = el.getAttribute('price');
arr.num = 1;
arr.id = id;
boughtList[id] = arr;
}
$scope.total = common.getTotal($scope.total);
}

$scope.delItem = function($event){
var li = $event.target.parentNode;
li.parentNode.removeChild(li);
var id = $event.target.getAttribute('item-id');
if(boughtList[id]){
delete boughtList[id];
}
$scope.total = common.getTotal($scope.total);
}
$scope.changeNum = function($event,num){
var id;
if(typeof $event == 'string'){
id = $event;
}else{
id = $event.target.parentNode.getAttribute('item-id');
}

boughtList[id].number = num;
$scope.total = common.getTotal($scope.total);
}
});

⑥ 2.在html中怎麼使一個div中的所有復選框全選和反選,寫出JS腳本。

var div=document.getElementById(div的id);
var chks=div.getElementsByName(checkbox的name); //checkbox設為同一個name
for(var i=0;i<chks.length;i++){
chks[i].checked;//全選
chks[i].checked=!內chks[i].checked //反選容
}

⑦ JS實現的「多復選框控制多DIV的顯隱」要怎樣簡化JS代碼

<divid="dd1">淘寶</div>
<divid="dd2">新浪</div>
<divid="dd3">網易</div>
<divid="dd4">天貓</div>

</div>
<inputtype="checkbox"id="ck1"value="dd1"/><labelfor="ck1">淘寶</label><br/>
<inputtype="checkbox"id="ck2"value="dd2"/><labelfor="ck2">新浪</label><br/>
<inputtype="checkbox"id="ck3"value="dd3"/><labelfor="ck3">網易</label><br/>
<inputtype="checkbox"id="ck4"value="ck4"/><labelfor="ck4">天貓</label><br/>

<scripttype="text/javascript">
$(":checkbox").each(function(){
$(this).click(function(){
if($(this).attr("checked")=="checked"){
$("#"+$(this).val()).hide();

}else{
$("#"+$(this).val()).show();
}
});

});
</script>

⑧ 勾選復選框實現隱藏div

<divclass="form-groupclearfix">
<divclass="tiaokuan_box">
<inputid="isyqm"name="isyqm"type="checkbox"checked="checked"class="check-input"onchange="cg(this)">
<span>使用邀請碼</span>
</div>
</div>
<divclass="form-groupclearfix">
<labelclass="form-label">邀請碼</label>
<divclass="lform-divyzm">
<inputclass="form-control"id="txtInviteCode"name="txtInviteCode"type="text">
</div>
</div>
<inputtype="hidden"id="yqm"name="yqm"value="1"/>


//000000000

varcg=function(ck){
vardiv=ck.parentElement
.parentElement
.nextElementSibling;
if(ck.checked){
div.style.display="block";
yqm.value=1;
}else{
div.style.display="none";
yqm.value=0;
}
}

⑨ css怎樣改變復選框的樣式

其實這個不能算是復選框了,用<span style="background:沒勾的圖"></span>
用JS控制,當你滑鼠點擊span的時候,改變他的background;就變成 這樣好看的

熱點內容
斷背山有幾分鍾 發布:2024-08-19 08:31:17 瀏覽:253
日本電影 女老師和學生私奔 發布:2024-08-19 08:29:36 瀏覽:49
台灣電影 雙胞胎 發布:2024-08-19 08:02:18 瀏覽:134
2020最新電影在線觀看網站 發布:2024-08-19 07:56:06 瀏覽:641
男男電影虐 發布:2024-08-19 07:04:57 瀏覽:10
韓國電影李采潭主演的關於發廊的 發布:2024-08-19 07:01:57 瀏覽:2
每期都有做的動漫 發布:2024-08-19 06:44:33 瀏覽:778
東宮拍攝時間 發布:2024-08-19 06:44:12 瀏覽:5
林正英電影情節鬼抬轎 發布:2024-08-19 06:36:35 瀏覽:254
懂的都懂在線觀看網站 發布:2024-08-19 06:26:11 瀏覽:676