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

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