日期:2014-05-16  浏览次数:20365 次

js自动算分功能
function SumNum()
	{
	var sumValue;
	s1=eval($("#score1").val());//score1是id,取值方法还有别种
	s2=eval($("#score2").val());
	s3=eval($("#score3").val());
	s4=eval($("#score4").val());
	s5=eval($("#score5").val());
	s6=eval($("#score6").val());
	s7=eval($("#score7").val());
	s8=eval($("#score8").val());
	
	if (isNaN(s1))//数字验证
	{s1=0;}
	if (isNaN(s2))
	{s2=0;}
	if (isNaN(s3))
	{s3=0;}
	if (isNaN(s4))
	{s4=0;}
	if (isNaN(s5))
	{s5=0;}
	if (isNaN(s6))
	{s6=0;}
	if (isNaN(s7))
	{s7=0;}
	if (isNaN(s8))
	{s8=0;}
	sumValue = s1+s2+s3+s4+s5+s6+s7+s8;
	$("#scoreSum").attr("value",sumValue);//求和赋值
	
	}

?

<tr>        <td>企业规模</td>        <td>注册资金</td>        <td>5</td>              <td class="queryCaseTd"><input type="text"  name="SCORE1" id="score1" size="30" maxlength="30"  onkeyup="value=value.replace(/[^\d\.]/g,'');SumNum();"/></td>        </tr>
<td class="queryLabelTd"><label>评价总得分(自动算得):</label></td>             <td class="queryCaseTd"><input type="text"   name="SCORE_SUM" id="scoreSum" size="30" maxlength="30" /></td>

? 要实现评分的自动算分使用了jquery,数字范围验证待加。。。

其中

JQuery获取input type="text"中的值的各种方式

$("#txt").attr("value");

$("#txt").val();

JavaScript eval() 函数

eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码。

语法

eval(string)
参数 描述
string 必需。要计算的字符串,其中含有要计算的 JavaScript 表达式或要执行的语句。

返回值

通过计算 string 得到的值(如果有的话)。

说明

该方法只接受原始字符串作为参数,如果 string 参数不是原始字符串,那么该方法将不作任何改变地返回。因此请不要为 eval() 函数传递 String 对象来作为参数。

如果试图覆盖 eval 属性或把 eval() 方法赋予另一个属性,并通过该属性调用它,则 ECMAScript 实现允许抛出一个 EvalError 异常。

?

JavaScript isNaN() 函数

isNaN() 函数用于检查其参数是否是非数字值。

语法

isNaN(x)

?

参数 描述
x 必需。要检测的值。

返回值

如果 x 是特殊的非数字值 NaN(或者能被转换为这样的值),返回的值就是 true。如果 x 是其他值,则返回 false。

说明

isNaN() 函数可用于判断其参数是否是 NaN,该值表示一个非法的数字(比如被 0 除后得到的结果)。

如果把 NaN 与任何值(包括其自身)相比得到的结果均是 false,所以要判断某个值是否是 NaN,不能使用 == 或 === 运算符。正因为如此,isNaN() 函数是必需的。

?一些其他别人的方法

<html>
<head>
<title> New Document </title>
<script language="javascript">
<!--
function add(var1,var2,var3)
{
	var result = 0;
	if(!isNaN(var1))
		result += var1;
	if(!isNaN(var2))
		result += var2;
	if(!isNaN(var3))
		result += var3;
	return result;
}
-->
</script>
</head>


<body>
<form name="form1">
<input type="text" name="text1" onblur="document.form1.text4.value=add(parseFloat(document.form1.text1.value),parseFloat(document.form1.text2.value),parseFloat(document.form1.text3.value));">
<input type="text" name="text2" onblur="document.form1.text4.value=add(parseFloat(document.form1.text1.value),parseFloat(document.form1.text2.value),parseFloat(document.form1.text3.value));">
<input type="text" name="text3" onblur="document.form1.text4.value=add(parseFloat(document.form1.text1.value),parseFloat(document.form1.text2.value),parseFloat(document.form1.text3.value));">
<input type="text" name="text4" >
</form>
</body>
</html>

?