Javascript使用Eval实现基本运算
效果图:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input id="num" type="text" />
<button onclick="eval1()">运算</button>
<label id="res"></label>
<script>
function eval1 () {
var num = document.getElementById("num").value;
var res1 = eval(num);
//alert(res1)
document.getElementById("res").innerText=res1;
}
</script>
</body>
</html>