購物車選中得到價格實現(xiàn)示例
更新時間:2014年01月26日 15:48:53 作者:
本文為大家介紹下購物車如何實現(xiàn)選中得到價格,下面有個不錯的示例,大家可以參考下
復制代碼 代碼如下:
<!DOCTYPE html>
<html>
<head>
<title>MyCart1.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script language = "javascript" type = "text/javascript">
function jisuan(obj){
var total = 0;
var fruits = document.getElementsByName("fruit");
for(var i=0;i<fruits.length;i++){
if(fruits[i].checked){
total += parseFloat(fruits[i].value);
}
}
myspan.innerText = total + "元";
}
</script>
</head>
<body>
<input type = "checkbox" name = "fruit" value = "10" onclick = "jisuan(this)">蘋果 10元<br/>
<input type = "checkbox" name = "fruit" value = "20" onclick = "jisuan(this)">香蕉 20元<br/>
<input type = "checkbox" name = "fruit" value = "30" onclick = "jisuan(this)">西瓜 30元<br/>
<input type = "checkbox" name = "fruit" value = "40" onclick = "jisuan(this)">栗子 40元<br/>
<input type = "checkbox" name = "fruit" value = "50" onclick = "jisuan(this)">哈密瓜 50元<br/><br/>
總價格是:<span id = "myspan">0元</span>
</body>
</html>
相關文章
JavaScript中利用for循環(huán)遍歷數(shù)組
這篇文章主要為大家詳細介紹了JavaScript中利用for循環(huán)遍歷數(shù)組,最好不要使用for in遍歷,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-01-01
JS與jQuery遍歷Table所有單元格內(nèi)容的方法
這篇文章主要介紹了JS與jQuery遍歷Table所有單元格內(nèi)容的方法,結合實例形式分別描述了JavaScript與jQuery實現(xiàn)遍歷table單元格的實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-12-12
延時重復執(zhí)行函數(shù) lLoopRun.js
延時重復執(zhí)行函數(shù) lLoopRun.js...2007-05-05
echarts tooltip自適應寬高讓提示框適應不同屏幕尺寸demo
這篇文章主要為大家介紹了echarts tooltip自適應寬高讓提示框適應不同屏幕尺寸,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-10-10

