2017年7月30日学习总结
一个小案例
简单计算器
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>demo</title>
<script>
function cal(){
var input = document.getElementById("calculate");
try{
input.value = eval(input.value);
}catch(e){
input.value = "输入错误!";
}
}
</script>
</head>
<body>
<h1>计算器</h1>
<input type="text" id="calculate" />
<input type="button" value="=" onclick="cal();"/>
</body>
</html>
网页结果
本文介绍了一个简单的网页版计算器实现方法,通过HTML和JavaScript构建,能够进行基本的数学运算,并且能够处理用户输入错误的情况。
81

被折叠的 条评论
为什么被折叠?



