简单计算机的编写

tyzz1269641562 2011-09-15 10:11:35

<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="text" name="text1" id="text1"/>
<select name="select" id="select">
<option value="add">+</option>
<option value="minus">-</option>
<option value="multiply">*</option>
<option value="divide">/</option></select>
<input type="text" name="text2" id="text2"/>
<input name="equel" type="button" id="equel" onclick="count()" value="="/>
<input type="text" name="text3" id="text3"/>
</label>
</form>
</body>
</html>
<script language="javascript">
function count()
{
var text1 = document.getElementById("text1");
var text2 = document.getElementById("text2");
var text3 = document.getElementById("text3");
var mark = document.getElementById("select").value;
if(mark == "add")
text3 = parseInt(text1) + parseInt(text2) ;
if(mark == "minus")
text3 = parseInt(text1) - parseInt(text2) ;
if(mark == "multiply")
text3 = parseInt(text1) * parseInt(text2) ;
if(mark == "divide")
text3 = parseInt(text1) / parseInt(text2) ;

}
</script>


大家帮忙看下为什么那个调用“count()”这个函数没有反应呢
...全文
105 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
最后一个菜鸟 2011-09-16
  • 打赏
  • 举报
回复
楼主为标题党
打字员 2011-09-16
  • 打赏
  • 举报
回复
晕,没被LZ黑死,计算机和计算器是不一样的。。。差好多。。。
WaistCoat08 2011-09-16
  • 打赏
  • 举报
回复
点击“结贴”
WaistCoat08 2011-09-16
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 tyzz1269641562 的回复:]

各位,这个分数怎么帮你们加呀,我不知道从哪儿加的
[/Quote]

点击“管理菜单”
tyzz1269641562 2011-09-16
  • 打赏
  • 举报
回复
各位,这个分数怎么帮你们加呀,我不知道从哪儿加的
tyzz1269641562 2011-09-16
  • 打赏
  • 举报
回复
抱歉哦,写错了
豆虫 2011-09-15
  • 打赏
  • 举报
回复
<html>
<head>

</head>
<body>
<form id="form1" name="form1" method="post" action="">

<input type="text" name="text1" id="text1"/>
<select name="select" id="select">
<option value="add">+</option>
<option value="minus">-</option>
<option value="multiply">*</option>
<option value="divide">/</option></select>
<input type="text" name="text2" id="text2"/>
<input name="equel" type="button" id="equel" onclick="count()" value="="/>
<input type="text" name="text3" id="text3"/>

</form>
</body>
</html>
<script language="javascript">
function count()
{
var text1 = document.getElementById("text1").value;
var text2 = document.getElementById("text2").value;
var text3 = document.getElementById("text3");
var mark = document.getElementById("select").value;
if(mark == "add")
text3.value = parseInt(text1) + parseInt(text2) ;
if(mark == "minus")
text3.value = parseInt(text1) - parseInt(text2) ;
if(mark == "multiply")
text3.value= parseInt(text1) * parseInt(text2) ;
if(mark == "divide")
text3.value= parseInt(text1) / parseInt(text2) ;

}
</script>
</body>
<html>
ycproc 2011-09-15
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 waistcoat08 的回复:]

getElementById返回的是对象,你的用它的value值才行。
if (mark == "add")
text3.value = parseInt(text1.value) + parseInt(text2.value) ;
[/Quote]
+1 正解
leecyz 2011-09-15
  • 打赏
  • 举报
回复
小东西,firebug,ie开发工具逐步调试。
WaistCoat08 2011-09-15
  • 打赏
  • 举报
回复
getElementById返回的是对象,你的用它的value值才行。
if (mark == "add")
text3.value = parseInt(text1.value) + parseInt(text2.value) ;
zjhsd2007 2011-09-15
  • 打赏
  • 举报
回复
text1 = document.getElementById("text1").value;
text3.value = ...
zjhsd2007 2011-09-15
  • 打赏
  • 举报
回复
text3.value = ...
WaistCoat08 2011-09-15
  • 打赏
  • 举报
回复
自己在count函数里用alert输出下提示定位错误行。

87,989

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧