日期:2014-05-17 浏览次数:20553 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript"> window.onload = function() { var obj = document.getElementsByName('abc[]'); var obj_count = document.getElementById('count'); for (var i = 0; i < obj.length; i ++) { obj[i].onkeyup = function() { var count = 0; for (var j = 0; j < obj.length; j ++) { var v = parseInt(obj[j].value) || 0; count += v; } obj_count.innerHTML = count; } } } </script> </head> <body> <input type=text name=abc[] value='' /> <br /> <input type=text name=abc[] value='' /> <br /> <input type=text name=abc[] value='' /> <br /> <input type=text name=abc[] value='' /> <br /> <input type=text name=abc[] value='' /> <br /> <input type=text name=abc[] value='' /> <br /> <input type=text name=abc[] value='' /> <br /> <input type=text name=abc[] value='' /> <br /> <input type=text name=abc[] value='' /> <br /> <div id="count"></div> </body> </html>
------解决方案--------------------
用parseFloat()代替parseInt()
------解决方案--------------------
额,可以js算好再ajax交上去,也可以做个表单直接交上去,也可以ajax直接交上去。