![]() |
#2
zmh8862010-11-14 12:03
|
大家看下例子:

<html>
<head>
<title>求和</title>
</head>
<body style=overflow:auto;>
<script>
intA=prompt("请输入第一个数",1);
intB=prompt("请输入第二个数",1);
document.write("<br>你输入第一个数"+intA);
document.write("<br>你输入第而个数"+intB);
document.write("<br>你输入两数之和"+(intA+intB));
</script>
</body>
</html>
这个JavaScript程序运行结果是:<head>
<title>求和</title>
</head>
<body style=overflow:auto;>
<script>
intA=prompt("请输入第一个数",1);
intB=prompt("请输入第二个数",1);
document.write("<br>你输入第一个数"+intA);
document.write("<br>你输入第而个数"+intB);
document.write("<br>你输入两数之和"+(intA+intB));
</script>
</body>
</html>
只有本站会员才能查看附件,请 登录
我想问下“+”即是连接字符,也是运算字符,为什么系统先识别连接字符,而不识别运算字符呢?
大家在看下这个程序:

<html>
<head>
<title>求和</title>
</head>
<body style=overflow:auto;>
<script>
document.write("1+1的结果是"+1+1);
document.write("<br>3*3的结果是"+3*3);
</script>
</body>
</html>
<head>
<title>求和</title>
</head>
<body style=overflow:auto;>
<script>
document.write("1+1的结果是"+1+1);
document.write("<br>3*3的结果是"+3*3);
</script>
</body>
</html>
只有本站会员才能查看附件,请 登录
这有是两码事,不一样的结果,我想了想,程序是先执行“*”后“+”,因为它们是按优先顺序执行的,为什么执行后结果是11呢?
[ 本帖最后由 流浪天边 于 2010-11-14 05:21 编辑 ]