webshow

JavaScript计算器,可以直接输入公式,然后按“计算”按钮,即可算出结果,学习JS运算的一个例子。

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312" />
<title>JavaScript计算器</title>
<script>
function calc(){
try{
document.getElementById(
"txt_formula").value = eval(document.getElementById("txt_formula").value);
}
catch(e){
document.getElementById(
"txt_formula").value = "错误的算式";
}
}
</script>
</head>
<body style="overflow:auto;">
<label>输入要计算的算式:</label>
<input id="txt_formula">
<input type="button" value="计算" onclick="calc();">
</body>
</html>

  

分类:

技术点:

相关文章:

  • 2021-11-21
  • 2021-11-21
  • 2021-11-21
  • 2021-11-21
  • 2021-12-10
  • 2021-12-29
  • 2021-11-19
  • 2021-11-21
猜你喜欢
  • 2021-12-28
  • 2021-12-28
  • 2021-12-16
  • 2021-11-21
  • 2021-12-16
  • 2021-11-17
  • 2021-11-17
  • 2021-11-20
相关资源
相似解决方案