<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <script> function fun(){ var year = document.getElementById('year').value; var month = document.getElementById('month').value; var day = document.getElementById('day').value; var sum_day;//總天數 sum_day = new Date(month + '-' + day + '-' + year); now_year = new Date().getFullYear(); one = new Date(1 + '-' + 1 + '-' + year); parseInt(Math.abs(sum_day - one) / 1000 / 60 / 60 /24); alert(parseInt(Math.abs(sum_day - one) / 1000 / 60 / 60 /24)+1); } </script> </head> <body> 年: <input type="number" id="year"/><br/> 月: <input type="number" id="month"/><br/> 日: <input type="number" id="day"/><br/> <input type="button" id="" value="計算" οnclick="fun()"/><br/> </body> </html>