| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 615 人关注过本帖
标题:初学vbscript 遇到问题
只看楼主 加入收藏
songyu611
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-9-1
收藏
 问题点数:0 回复次数:1 
初学vbscript 遇到问题


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>计算器</title>
</head>

<body>

<script language="vbscript">
on error resume next
dim expression
sub addv(cv)
cv=trim(cv)
if( (cv="+") or (cv="-") or (cv="*") or (cv="\")) then
document.f1.resu.value=""
if (right(expression,1)="" or right(expression,1)="+" or right(expression,1)="-" or right(expression,1)="*" or right(expression,1)="\" )then
msgbox("这样无法计算")
expression=""
exit sub
end if
end if


expression=expression&cv
document.f1.resu.value=expression
end sub
sub compute()
document.f1.resu.value=eval(expression)
expression=document.f1.resu.value
end sub
sub crt()
expression=""
document.f1.resu.value=""
end sub
</script>
<form name="f1">
<div align="center">
<table width="200" border="1" cellspacing="0" cellpadding="0">
<tr>
<td colspan="4" align="center">青蛙计算机</td>
</tr>
<tr>
<td colspan="4"><div align="center">
<input type="text" name="resu">
</div></td>
</tr>
<tr>
<td><div align="center">
<input type="button" value=" 1 " name="v1" onClick="addv('1')">
</div></td>
<td><div align="center">
<input type="button" value=" 2 " name="v2" onClick="addv('2')">
</div></td>
<td><div align="center">
<input type="button" value=" 3 " name="v3" onClick="addv('3')">
</div></td>
<td><div align="center">
<input type="button" value=" + " name="plus" onClick="addv('+')">
</div></td>
</tr>
<tr>
<td><div align="center">
<input type="button" value=" 4 " name="v4" onClick="addv('4')">
</div></td>
<td><div align="center">
<input type="button" value=" 5 " name="v5" onClick="addv('5')">
</div></td>
<td><div align="center">
<input type="button" value=" 6 " name="v6" onClick="addv('6')">
</div></td>
<td><div align="center">
<input type="button" value=" - " name="minu" onClick="addv('-')">
</div></td>
</tr>
<tr>
<td><div align="center">
<input type="button" value=" 7 " name="v7" onClick="addv('7')">
</div></td>
<td><div align="center">
<input type="button" value=" 8 " name="v8" onClick="addv('8')">
</div></td>
<td><div align="center">
<input type="button" value=" 9 " name="v9" onClick="addv('9')">
</div></td>
<td><div align="center">
<input type="button" value=" * " name="mult" onClick="addv('*')">
</div></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="button" value=" = " name="eqal" onClick="compute()">
</div></td>
<td><input type="button" value=" CR " name="cr" onClick="crt()"></td>
<td><div align="center">
<input type="button" value=" \ " name="divi" onClick="addv('\')">
</div></td>
</tr>
</table>
</div>
</form>
</body>
</html>
一个计算器的例子,在文本框里输入数字后 用鼠标去掉 在输入数字,去掉的数字又出来了 请问怎么修改

9JIM4rut.rar (1.22 KB) 初学vbscript 遇到问题


搜索更多相关主题的帖子: vbscript expression 计算器 right 
2007-09-01 19:26
jkll007123
Rank: 1
等 级:新手上路
威 望:1
帖 子:64
专家分:0
注 册:2007-7-8
收藏
得分:0 

加上这段:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>计算器</title>
</head>

<body>

<script language="vbscript">
on error resume next
dim expression
sub addv(cv)
cv=trim(cv)
if( (cv="+") or (cv="-") or (cv="*") or (cv="\")) then
document.f1.resu.value=""
if (right(expression,1)="" or right(expression,1)="+" or right(expression,1)="-" or right(expression,1)="*" or right(expression,1)="\" )then
msgbox("这样无法计算")
expression=""
exit sub
end if
end if


expression=expression&cv
document.f1.resu.value=expression
end sub
sub compute()
document.f1.resu.value=eval(expression)
expression=document.f1.resu.value
end sub
sub crt()
expression=""
document.f1.resu.value=""
end sub
sub clear()
if document.f1.resu.value="" then
document.f1.resu.value=""
expression=""
else
expression=""
document.f1.resu.value=document.f1.resu.value&cv
expression=document.f1.resu.value
end if
end sub

</script>

<form name="f1">
<div align="center">
<table width="200" border="1" cellspacing="0" cellpadding="0">
<tr>
<td colspan="4" align="center">青蛙计算机</td>
</tr>
<tr>
<td colspan="4"><div align="center">
<input type="text" name="resu" onblur="clear()">
</div></td>
</tr>
<tr>
<td><div align="center">
<input type="button" value=" 1 " name="v1" onClick="addv('1')">
</div></td>
<td><div align="center">
<input type="button" value=" 2 " name="v2" onClick="addv('2')">
</div></td>
<td><div align="center">
<input type="button" value=" 3 " name="v3" onClick="addv('3')">
</div></td>
<td><div align="center">
<input type="button" value=" + " name="plus" onClick="addv('+')">
</div></td>
</tr>
<tr>
<td><div align="center">
<input type="button" value=" 4 " name="v4" onClick="addv('4')">
</div></td>
<td><div align="center">
<input type="button" value=" 5 " name="v5" onClick="addv('5')">
</div></td>
<td><div align="center">
<input type="button" value=" 6 " name="v6" onClick="addv('6')">
</div></td>
<td><div align="center">
<input type="button" value=" - " name="minu" onClick="addv('-')">
</div></td>
</tr>
<tr>
<td><div align="center">
<input type="button" value=" 7 " name="v7" onClick="addv('7')">
</div></td>
<td><div align="center">
<input type="button" value=" 8 " name="v8" onClick="addv('8')">
</div></td>
<td><div align="center">
<input type="button" value=" 9 " name="v9" onClick="addv('9')">
</div></td>
<td><div align="center">
<input type="button" value=" * " name="mult" onClick="addv('*')">
</div></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="button" value=" = " name="eqal" onClick="compute()">
</div></td>
<td><input type="button" value=" CR " name="cr" onClick="crt()"></td>
<td><div align="center">
<input type="button" value=" \ " name="divi" onClick="addv('\')">
</div></td>
</tr>
</table>
</div>
</form>
</body>
</html>


習慣瞇醉,禧歡跟上帝窷兲,像变澀龙般虚伪,如气候那样善变.人脸背后流淌着恶魔的血,一路向前,猦猦癫癫.
2007-09-01 20:49
快速回复:初学vbscript 遇到问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033807 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved