購物車選中得到價(jià)格實(shí)現(xiàn)示例
更新時(shí)間:2014年01月26日 15:48:53 作者:
本文為大家介紹下購物車如何實(shí)現(xiàn)選中得到價(jià)格,下面有個(gè)不錯(cuò)的示例,大家可以參考下
復(fù)制代碼 代碼如下:
<!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/>
總價(jià)格是:<span id = "myspan">0元</span>
</body>
</html>

相關(guān)文章
d3.js入門教程之?dāng)?shù)據(jù)綁定詳解
這篇文章主要介紹了關(guān)于d3.js數(shù)據(jù)綁定的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)只d3.js具有一定的參考價(jià)值,需要的朋友下面來一起看看吧。2017-04-04javascript中mouseenter與mouseover的異同
javascript中mouseover和mouseenter的區(qū)別主要在于監(jiān)聽對(duì)象的子元素是否觸發(fā)事件。mouseover:鼠標(biāo)移入監(jiān)聽對(duì)象中,或者從監(jiān)聽對(duì)象的一個(gè)子元素移入另一個(gè)子元素中時(shí)觸發(fā)該事件。mouseenter:鼠標(biāo)移入監(jiān)聽對(duì)象時(shí)觸發(fā),在監(jiān)聽對(duì)象內(nèi)移動(dòng)不會(huì)觸發(fā)。2017-06-06JS簡單實(shí)現(xiàn)點(diǎn)擊復(fù)制鏈接的方法
這篇文章主要介紹了JS簡單實(shí)現(xiàn)點(diǎn)擊復(fù)制鏈接的方法,提供了2種簡單的復(fù)制鏈接操作方法供大家選擇使用,需要的朋友可以參考下2016-08-08每天一篇javascript學(xué)習(xí)小結(jié)(基礎(chǔ)知識(shí))
這篇文章主要介紹了javascript基本的知識(shí)點(diǎn),包括字符串、特殊字符運(yùn)算、變量轉(zhuǎn)字符串等,對(duì)javascript的基礎(chǔ)知識(shí)講解的很全面,為了更好地幫助大家學(xué)習(xí)javascript,感興趣的小伙伴們可以參考一下2015-11-11JS判斷鍵盤是否按的回車鍵并觸發(fā)指定按鈕點(diǎn)擊操作的方法
下面小編就為大家?guī)硪黄狫S判斷鍵盤是否按的回車鍵并觸發(fā)指定按鈕點(diǎn)擊操作的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02