gpt4 book ai didi

javascript - 将相同的值发送到另一个变量?

转载 作者:行者123 更新时间:2023-11-28 19:30:16 27 4
gpt4 key购买 nike

我必须形成页面,并且如果用户代理是移动的,我正在尝试将相同的值发送到另一个变量(linkmobile)。您能告诉我最少编码的最佳方法是什么吗?

  var link = "reservation.html?";
var linkmobile = "reservation-mobile.html?";

link += "checkinYear="+ checkinYear;
link += "&checkinDay="+ checkinDay;
link += "&checkinMonth="+ checkinMonth;

if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|OperaMini/i.test(navigator.userAgent)) {
window.location.href = link-mobile;
}
else
window.location.href = link;

}

最佳答案

试试这个:

    var link = "reservation.html?";  

if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|OperaMini/i.test(navigator.userAgent)) {
link = "reservation-mobile.html?";
}

link += "checkinYear="+ checkinYear;
link += "&checkinDay="+ checkinDay;
link += "&checkinMonth="+ checkinMonth;

window.location.href = link;
}

关于javascript - 将相同的值发送到另一个变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26962708/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com