js 两数 的 加减乘数 运算
2016-01-30 17:51
501 查看
<body> <input type="text" name="text1" id="text1" value=""/> <select name="" id="myselect"> <option value="+">+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">/</option> </select> <input type="text" name="text2" id="text2" value=""/> <input type="button" value=" = " onclick="end();"/> <input type="text" name="text3" id="text3" value=""/> </body> <script> function end(){ var text1 = document.getElementById("text1").value; var text2 = document.getElementById("text2").value; var text3; var s = document.getElementById("myselect"); var num = s.options[s.selectedIndex].text; switch(num){ case "+": document.getElementById("text3").value = parseInt(text1)+parseInt(text2); break; case "-": document.getElementById("text3").value = parseInt(text1)-parseInt(text2); break; case "*": document.getElementById("text3").value = parseInt(text1)*parseInt(text2); break; case "/": document.getElementById("text3").value = parseInt(text1)/parseInt(text2); break; } } </script>
相关文章推荐
- 关于js中单引号(')和双引号(")的使用以及转义的理解
- JS转换HTML转义符
- JavaScript实现tab选项卡(多种方式)
- 第2章{2-1什么是模块系统}
- JavaScript与Java的区别
- js正则表达式简单例子
- JavaScript基础总结
- JS排序方法(sort,bubble,select,insert)代码汇总
- JavaScript While循环
- Javascript中for循环
- JavaScript中的this机制
- 廖雪峰的个人站点:里面有他写的 python javascript git 教程。很不错的样子
- 前端基础之JavaScript
- Handlebars.js 模板引擎
- js 创建对象
- js判断浏览器的类型和获得浏览器的版本
- webapi之jsonp调用
- 用AFNetworking 做JSON数据解析遇到 3840 错误
- js如何实现继承
- jsonp调用webapi和mvc