日期:2014-05-18  浏览次数:20765 次

js获取文本框值后怎么取得总和
用js实现一个添加试题功能,可以添加很多试题,每次添加后每题有一个分数值,取得后最后计算出添加的总分,已经能够获取每个文本框的值,但是怎么循环相加那?js代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
var $ = document.getElementById;
var n = 0; 
 
//以下方法为创建新的Table
function addMyTable(){   
 
    var target = $("target");
    n = n+1;
var tr = target.insertRow();
tr.height="25";
tr.style.backgroundColor="#E6F7DF";
var td6 = tr.insertCell();
td6.className = "notprint";
td6.align="center";
 
//问题描述
tr.insertCell().innerHTML="<td width='165'>"+
"<textarea style='border:0px;' name='title' id='cyuserid"+n+"'/>";
   //选项a
   tr.insertCell().innerHTML="<td width='100'>"+
          "<input type='text' style='border:none;width:100px;' id='type"+n+"' name='type' size='6'  />"+
             
        "</td>";
        
        //选项b
    tr.insertCell().innerHTML="<td width='100'>"+
          "<input type='text' style='border:none;width:100px;' id='danw"+n+"' name='danw' size='5' />"+
        "</td>";                        
    //选项c
    tr.insertCell().innerHTML="<td width='100'>"+
          "<input type='text' style='border:none;width:100px;' id='shul"+n+"' name='shul'/>"+
        "</td>";             
    //选项d 
    tr.insertCell().innerHTML="<td width='100'>"+
    "<input type='text' style='border:none; width:100px;'  name='ryid' id='ryid"+n+"' />"+   
       "</td>";
    //标准答案