<div class="codetitle"> <span><a style="CURSOR: pointer" data="45444" class="copybut" id="copybut45444" onclick="doCopy('code45444')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code45444"> <br> <br> <br> <br><title>MyCart1.html</title> <br><br><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <br><meta http-equiv="description" content="this is my page"> <br><meta http-equiv="content-type" content="text/html; charset=UTF-8"> <br><br><!--<link rel="stylesheet" type="text/css" href="./styles.css">--> <br><script language="javascript" type="text/javascript"> <br><br>function jisuan(obj){ <br><br>var total = 0; <BR>var fruits = document.getElementsByName("fruit"); <BR>for(var i=0;i<fruits.length;i++){ <BR>if(fruits[i].checked){ <BR>total += parseFloat(fruits[i].value); <BR>} <BR>} <BR>myspan.innerText = total + "元"; <BR>} <BR></script> <br> <br><br> <br><input type="checkbox" name="fruit" value="10" onclick="jisuan(this)">苹果 10元<br> <br><input type="checkbox" name="fruit" value="20" onclick="jisuan(this)">香蕉 20元<br> <br><input type="checkbox" name="fruit" value="30" onclick="jisuan(this)">西瓜 30元<br> <br><input type="checkbox" name="fruit" value="40" onclick="jisuan(this)">栗子 40元<br> <br><input type="checkbox" name="fruit" value="50" onclick="jisuan(this)">哈密瓜 50元<br><br> <br>总价格是:<span id="myspan">0元</span> <br> <br> <br> </div> <br><img src="http://files.jb51.net/file_images/article/201401/20140126155233.png?201402615533" alt="购物车选中得到价格实现示例_javascript技巧" >