如果 30-41 歲 > 按鈕 > 去一個網站.......
否則 42-99 歲 > 相同按鈕 > 轉到另一個網站。
這是我的代碼:https : //drive.google.com/file/d/1iqCo2CuvPP5Sm_olIZFoovXBlsiG0H6o/view?usp=sharing
uj5u.com熱心網友回復:
JavaScript 是來拯救的。
HTML:
<button onclick="navigation()">Click</button>
JavaScript
<script>
function navigation(){
var age = 40; // Not sure how you detect age
if (age>=30 && age<=41)
window.open("http://www.website1.com");
else if (age>=42 && age<=99)
window.open("http://www.website2.com");
}
</script>
uj5u.com熱心網友回復:
繼承人您的 html 與更改的代碼。享受!:)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Add your Age</title>
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="datepicker.js"></script>
</head>
<body>
<select id="dobday"></select>
<select id="dobmonth"></select>
<select id="dobyear"></select>
<button id="buttonOK" style="margin-left: 40px;background:orange;padding: 10px 25px; " >Ok</button>
<script>
$(document).ready(function() {
$.dobPicker({
daySelector: '#dobday', /* Required */
monthSelector: '#dobmonth', /* Required */
yearSelector: '#dobyear', /* Required */
dayDefault: 'Day', /* Optional */
monthDefault: 'Month', /* Optional */
yearDefault: 'Year', /* Optional */
minimumAge: 18, /* Optional */
maximumAge: 99 /* Optional */
});
});
$( "#buttonOK" ).click(function() {
const yearDiff = new Date().getFullYear() - $("#dobyear").find(":selected").text();
if( yearDiff > 30 && yearDiff < 41){
window.location.href = "http://stackoverflow.com";
}
else if(yearDiff >= 41 && yearDiff < 99){
window.location.href = "http://google.com";
}
else{
window.location.href = "http://yahoo.com";
}
});
</script>
</body>
</html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/377618.html
標籤:javascript html 查询 jquery-ui
