<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p>x的值为: <input type="text"id="num1" placeholder="请输入不为0的数字"/></p>
<p>y的值为: <input type="text" id="num2" placeholder="请输入任意数字" /></p>
<p><input type="button" id="sub" value="确定" onclick="myfun()"/></p>
<p>结果为:<span id="res"></span></p>
<script type="text/javascript">
function myfun () {
var x=document.getElementById("num1").value;
var y=document.getElementById("num2").value;
var jg=document.getElementById("res");
var sum=1;
var i=1;
for (i;i<=y;i++) {
sum=Math.pow(x,y);//第一种方法
//sum=sum*x;//第二种方法
}
jg.innerHTML=sum;
}
</script>
</body>
</html>