首页上一页 1 下一页尾页 2 条记录 1/1页
JavaScript报错, 网页上有错误 怎么也跑不起来,请哪位哥哥姐姐帮忙看看啊!!!!
发表在JavaWeb图书答疑
2010-08-31
是否精华
是
否
版块置顶:
是
否
<html>
<head><title>sum(arg11,arg12)</title></head>
<body>
<script language="javascript">
function sum(arg11,arg12)
{
var arg1=new String(arg11);
var arg2=new String(arg12);
if ( (arg1=="") || (arg2=="") )
{
var e0=new Error();
e0.Serial=1000001;
if (arg1=="")
{
e0.message="sum函数非法,第一个参数为空";
}
else
{
e0.message="sum函数非法,第二个参数为空";
}
throw e0;
}
for (int i=0;i<arg1.length; i++ )
{
for (int j=0;j<10; j++ )
{
if (arg1.charAt(i)==j)
{
break;
}
else
{
if (j==9)
{
var e1=new Error();
e1.Serial=1000001;
e1.message="sum函数非法,参数不是数字";
throw e1;
}
}
}
}
for (int k=0;k<arg2.length; k++ )
{
for (int l=0;l<10; l++ )
{
if (arg2.charAt(k)==l)
{
break;
}
else
{
if (l==9)
{
var e2=new Error();
e2.Serial=1000001;
e2.message="sum函数非法,参数不是数字";
throw e2;
}
}
}
}
return Number(arg11)+Number(arg12);
}
function Button1_onclick()
{
try
{
var t1=document.getElementById("text1");
var t2=document.getElementById("text2");
var t3=document.getElementById("text3");
var sm=sum(t1.value,t2.value);
t3.value=sm;
}
catch (e)
{
alert(e.message);
if (e.Serial==1000001)
{
alert(e.message);
e=null;
}
}
}
</script>
<input id="text1" type="text" />+
<input id="text2" type="text" />=
<input id="text3" type="text" />
<input id="Button1" type="button" value="计算" onclick="return Button1_onclick()" />
</body>
</html>
<head><title>sum(arg11,arg12)</title></head>
<body>
<script language="javascript">
function sum(arg11,arg12)
{
var arg1=new String(arg11);
var arg2=new String(arg12);
if ( (arg1=="") || (arg2=="") )
{
var e0=new Error();
e0.Serial=1000001;
if (arg1=="")
{
e0.message="sum函数非法,第一个参数为空";
}
else
{
e0.message="sum函数非法,第二个参数为空";
}
throw e0;
}
for (int i=0;i<arg1.length; i++ )
{
for (int j=0;j<10; j++ )
{
if (arg1.charAt(i)==j)
{
break;
}
else
{
if (j==9)
{
var e1=new Error();
e1.Serial=1000001;
e1.message="sum函数非法,参数不是数字";
throw e1;
}
}
}
}
for (int k=0;k<arg2.length; k++ )
{
for (int l=0;l<10; l++ )
{
if (arg2.charAt(k)==l)
{
break;
}
else
{
if (l==9)
{
var e2=new Error();
e2.Serial=1000001;
e2.message="sum函数非法,参数不是数字";
throw e2;
}
}
}
}
return Number(arg11)+Number(arg12);
}
function Button1_onclick()
{
try
{
var t1=document.getElementById("text1");
var t2=document.getElementById("text2");
var t3=document.getElementById("text3");
var sm=sum(t1.value,t2.value);
t3.value=sm;
}
catch (e)
{
alert(e.message);
if (e.Serial==1000001)
{
alert(e.message);
e=null;
}
}
}
</script>
<input id="text1" type="text" />+
<input id="text2" type="text" />=
<input id="text3" type="text" />
<input id="Button1" type="button" value="计算" onclick="return Button1_onclick()" />
</body>
</html>