JavaScript代码
var num1 = document.getElementById("num1")var num2 = document.getElementById("num2")var bol = document.getElementById("bol")var span = document.querySelector("span")var btn = document.getElementById("btn")
btn.onclick=function(){var n =parseFloat(num1.value);var m =parseFloat(num2.value);var b = bol.value;var s =0;switch(b){case"+":
s = n + m;break;case"-":
s = n - m;break;case"*":
s = n * m;break;case"/":
s = n / m;break;case"%":
s = n % m;break;}
span.innerHTML = s;}
JavaScript代码
var num1 = document.getElementById("num1");var num2 = document.getElementById("num2");var num3 = document.getElementById("num3");var btn = document.getElementById("btn");var span = document.querySelector("span")var n =parseInt(num1.value)var sum =0
btn.onclick=function(){switch(num2.value){case"12":
sum +=30;case"11":
sum +=31;case"10":
sum +=30;case"9":
sum +=31;case"8":
sum +=31;case"7":
sum +=30;case"6":
sum +=31;case"5":
sum +=30;case"4":
sum +=31;case"3":if(n%4===0&&n%100!==0||n%400===0){
sum +=29;}else{
sum +=28;}case"2":
sum +=31;case"1":
sum +=parseInt(num3.value);break;default:
span.innerHTML ="你所输入的时间不符"}
span.innerHTML ="这是"+ num1.value+"的第"+sum+"天";}