<div>
  <span>圓的直徑 = </span>
  <input type="text" class="diameter" placeholder="diameter here.">
</div>
<p>圓面積 = <span class="circleArea"></span></p>
// 宣告常數PI,並給定值3.1415926
const PI = 3.1415926;

$(".diameter").keyup(function(){
  // 取得直徑的值
  var num = $('.diameter').val();
  // 計算圓面積
  $(".circleArea").text(num * PI);
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js