就是這個(gè)樣的粗爆,手搓一個(gè)計(jì)算器:經(jīng)期計(jì)算器

線上運(yùn)行,可以直接打開:經(jīng)期計(jì)算器(在線計(jì)算器)

? ? ? ?作為程序員,沒有合適的工具,就得手搓一個(gè),PC端,移動(dòng)端均可適用。廢話不多說,直接上代碼。

HTML:

<div class="calculator"><label for="lastPeriod">上次月經(jīng)日期:</label> <input id="lastPeriod" type="date" placeholder="選擇上次月經(jīng)日期"> <label for="cycleLength">經(jīng)期周期長度 (天):</label> <input id="cycleLength" type="number" placeholder="輸入經(jīng)期周期長度"><button onclick="calculatePeriod()">計(jì)算</button><div id="result" class="result">結(jié)果將顯示在這里</div></div>

JS:

function calculatePeriod() { const lastPeriodDate = new Date(document.getElementById('lastPeriod').value); const cycleLength = parseInt(document.getElementById('cycleLength').value); if (isNaN(lastPeriodDate.getTime()) || isNaN(cycleLength)) { document.getElementById('result').textContent = "請(qǐng)輸入有效的日期和周期長度。"; return; } // 預(yù)測下一次月經(jīng)的日期 const nextPeriodDate = new Date(lastPeriodDate); nextPeriodDate.setDate(lastPeriodDate.getDate() + cycleLength); // 預(yù)測排卵期(一般為周期的中間) const ovulationDate = new Date(lastPeriodDate); ovulationDate.setDate(lastPeriodDate.getDate() + cycleLength / 2); document.getElementById('result').innerHTML = `下一次月經(jīng)日期:${nextPeriodDate.toLocaleDateString()}<br>` + `預(yù)計(jì)排卵日期:${ovulationDate.toLocaleDateString()}`; }

?CSS:

.calculator { width: 100%; background-color: #333; color: white; padding: 20px; border-radius: 10px; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3); } label { display: block; margin-bottom: 10px; font-size: 16px; } input, select { width: 100%!important; padding: 10px!important; margin-bottom: 20px; color: #000000; border-radius: 5px; border: 1px solid #555; font-size: 16px!important; background-color: #ffffff!important; } button { width: 100%; padding: 10px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer; font-size: 16px; } button:hover { background-color: orange; } .result { font-size: 18px; margin-top: 20px; text-align: center; } option { background-color: #ffffff; } p { font-size: 18px; margin-top: 5px!important; }

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容