如何根据年龄点击两个不同页面的按钮来重定向?
How can I redirect by clicking button two different page based on age?
如果 30-41 岁 >按钮 > 转到网站......
Otherwish 42-99 years > same button >go to another website.
这是我的代码:
https://drive.google.com/file/d/1iqCo2CuvPP5Sm_olIZFoovXBlsiG0H6o/view?usp=sharing
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>
这是您的 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://whosebug.com";
}
else if(yearDiff >= 41 && yearDiff < 99){
window.location.href = "http://google.com";
}
else{
window.location.href = "http://yahoo.com";
}
});
</script>
</body>
</html>
如果 30-41 岁 >按钮 > 转到网站......
Otherwish 42-99 years > same button >go to another website.
这是我的代码: https://drive.google.com/file/d/1iqCo2CuvPP5Sm_olIZFoovXBlsiG0H6o/view?usp=sharing
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>
这是您的 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://whosebug.com";
}
else if(yearDiff >= 41 && yearDiff < 99){
window.location.href = "http://google.com";
}
else{
window.location.href = "http://yahoo.com";
}
});
</script>
</body>
</html>