<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><!DOCTYPE html> <br> <br> <br><title>MyCart1.html</title> <br><br><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <br><meta http-equiv="description" content="これは私のページです"> <br><meta http-equiv="content-type" content="text/html; charset=UTF-8"> <br><br><!--<link rel="stylesheet" type="text/css" href="./styles.css">--> <br><スクリプト言語 = "javascript" タイプ = "text/javascript"> <br><br>関数 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></head> <br><br> <br>苹果 10元<br> <br><input type = "checkbox" name = "fruit" value = "20" onclick = "jisuan(this)">香蕉 20元<br/>; <BR><入力タイプ = "チェックボックス" 名前 = "フルーツ" 値 = "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/> <BR>总价格是:<span id = "myspan">0元</span> <br></body> <br></html> <br> </div> <br><img src="http://files.jb51.net/file_images/article/201401/20140126155233.png?201402615533" alt="ショッピングカート選択後の価格取得例_JavaScriptスキル" >