有多个按钮 1-9等等 如何用js实现点击按钮将按钮的ValuE的值传到文本框
2条回答
- dreamhighhigh 2014-12-04 07:42关注
``<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script language="javascript"> function test(str) { var x=document.getElementById("one").value; var y=document.getElementById("two").value; var t1; switch(str) {case "+":t1=parseInt(x)+parseInt(y);break; case "-":t1=parseInt(x)-parseInt(y);break; case "*":t1=parseInt(x)*parseInt(y);break; case "/":t1=parseInt(x)/parseInt(y); } document.getElementById("result").value=t1; } </script> </head> <body>一个数:<input type="text" id="one"><br/> 另一个数:<input type="text" id="two"><br/> 结果:<input type="text" id="result"><br/> <input type="button" value="+" onclick="test('+')"/><input type="button" value="-" onclick="test('-')"/><input type="button" value="*" onclick="test('*')"/><input type="button" value="/" onclick="test('/')"/> </body> </html> `
解决 无用评论 打赏 举报
悬赏问题
- ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
- ¥20 腾讯企业邮箱邮件可以恢复么
- ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
- ¥15 错误 LNK2001 无法解析的外部符号
- ¥50 安装pyaudiokits失败
- ¥15 计组这些题应该咋做呀
- ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
- ¥15 让node服务器有自动加载文件的功能
- ¥15 jmeter脚本回放有的是对的有的是错的
- ¥15 r语言蛋白组学相关问题