DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript綜合知識 >> 購物車選中得到價格實現示例
購物車選中得到價格實現示例
編輯:JavaScript綜合知識     

 本文為大家介紹下購物車如何實現選中得到價格,下面有個不錯的示例,大家可以參考下

代碼如下: <!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> 
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved