欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript計(jì)算正方形面積

 更新時(shí)間:2019年11月26日 08:39:32   作者:若年封塵  
這篇文章主要為大家詳細(xì)介紹了JavaScript計(jì)算正方形面積,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

用JavaScript實(shí)現(xiàn)計(jì)算正方形的面積注意用一個(gè)Math.pow()函數(shù)。

實(shí)現(xiàn)效果:

實(shí)現(xiàn)代碼:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Document</title>
</head>
<body>
 <form method="get" action="">
  <h2>計(jì)算正方形的面積</h2>
  正方形的邊長(zhǎng):<input type="text" id="radius"><br>
  正方形的面積:<input type="text" readonly="readonly" id="area"><br>
  <input type="button" value="計(jì)算" onclick="show()" />
  <input type="reset" value="重置" />
 </form>
</body>
<script type="text/javascript">
 function area(radius){
  var radius=document.getElementById("radius").value;//獲取正方形的邊長(zhǎng)
  var area=Math.pow(radius,2);//計(jì)算正方形的面積
  return area;
 }
 function show(){
  //輸出正方形的面積
  document.getElementById("area").value=area(radius);
 }
</script>
</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論