首页 > 解决方案 > 带有时刻 js 的时区选择器在 IE11 中不起作用

问题描述

//TimeZone

/*const z_t = (s) => {
    if (i18n !== void 0 && i18n[s]) {
        return i18n[s];
    }

    return s;
};*/
const z_t = function(s) {
    if (i18n !== void 0 && i18n[s]) {
        return i18n[s];
    }

    return s;
};
const timezones = [
    "Etc/GMT+12",
    "Pacific/Midway",
    "Pacific/Auckland",
    "Pacific/Tongatapu",
];

const i18n = {
    "Etc/GMT+12": "International Date Line West",
    "Pacific/Midway": "Midway Island, Samoa",
    "Pacific/Honolulu": "Hawaii",
    "Pacific/Tongatapu": "Nuku'alofa",
};

const selectorOptions = moment.tz
    .names()
    .filter((tz) => {
        return timezones.includes(tz);
    })
    .reduce((memo, tz) => {
        memo.push({
            name: tz,
            offset: moment.tz(tz).utcOffset(),
        });

        return memo;
    }, [])
    .sort((a, b) => {
        return a.offset - b.offset;
    })
    .reduce((memo, tz) => {
        const timezone = tz.offset ? moment.tz(tz.name).format("Z") : "";

        return memo.concat(
            `<option value="${tz.name}">(GMT${timezone}) ${z_t(tz.name)}</option>`
        );
    }, "");
let js_Selector = document.querySelector(".js-Selector");
console.log(js_Selector);
if (js_Selector) {
    js_Selector.innerHTML = selectorOptions;
    js_Selector.value = "Europe/Brussels";
    const event = new Event("change");
    js_Selector.dispatchEvent(event);
}

$(".js-Selector").select2();

我正在使用带有时刻 js 的时区选择器来选择时区。它工作正常,但在 IE11 上它不起作用。它的 bcoz 中有一些箭头功能。我尝试更正但它不起作用。因为我是新手请帮忙我来解决这个问题。无论如何,提前感谢您的帮助

标签: javascriptjquery

解决方案


推荐阅读