3 回答

TA貢獻1851條經驗 獲得超5個贊
只需使用并操作它會幫助您檢查 2 個條件
function myfun(){
//var yofad = document.getElementById('age').value;
var yoad;
var year = 2014 ;
if( year >= 2014 && year <2019){
yoad = "Your certicate is ready go to school portal";
}else if (year == 2019){
yoad = "Your certificate is in progress";
} else {
yoad = "cert not found";
}
document.getElementById('cc').innerHTML=yoad
}

TA貢獻1859條經驗 獲得超6個贊
將您的第一個條件限制為小于 2019,否則對于 2019、2020 和其他更大的值也將成立。改為if(year >= 14)_if(year >= 14 && year <2019)
function myfun(){
var year = document.getElementById('age').value;
var yoad;
if( year >= 2014 && year < 2019){
yoad = "Your certicate is ready go to school portal";
} else if (year == 2019){
yoad = "Your certificate is in progress";
} else {
yoad = "cert not found";
}
document.getElementById('cc').innerHTML=yoad
}
<h6>Enter your year of admission to know if your certificate is ready</h6>
<input id="age">
<button onclick="myfun()">enter</button>
<p id="xc"></p>
<p id="cc"></p>

TA貢獻1860條經驗 獲得超8個贊
function myfun(){
document.getElementById('cc').innerHTML = "";
const value = document.getElementById('age').value;
if (!value) return;
const year = parseInt(value);
let yoad;
if (year > 2019) {
yoad = "certicate not read";
} else if (year >= 2014 && year <= 2019) {
yoad = "Your certicate is ready go to school portal";
} else {
yoad = "cert not found";
}
document.getElementById('cc').innerHTML = yoad
}
<h6>Enter your year of admission to know if your certificate is ready</h6>
<input id="age">
<button onclick="myfun()">enter</button>
<p id="xc"></p>
<p id="cc"></p>
也許你需要這樣的東西!
添加回答
舉報