1
<p id="demo">单击按钮显示不同数值的平方根。</p>
2
<button onclick="myFunction()">点我</button>
3
<script>
4
function myFunction() {
5
var a = Math.sqrt(0);
6
var b = Math.sqrt(1);
7
var c = Math.sqrt(9);
8
var d = Math.sqrt(64);
9
var e = Math.sqrt(-9);
10
var x = document.getElementById("demo")
11
x.innerHTML = a + "<br>" + b + "<br>" + c + "<br>" + d + "<br>" + e;
12
}
13
</script>