gpt4 book ai didi

javascript - 通过 javascript 为移动设备转换为选择选项的列表,不适用于 IOS 移动浏览器

转载 作者:行者123 更新时间:2023-11-29 05:45:55 24 4
gpt4 key购买 nike

我正在尝试使用适用于移动设备的 javascript 创建选择选项,数据来自链接列表,但它不仅仅适用于 IOS。

这是列表来自链接的位置

var listSelect = document.querySelector(".epgtvm_select-country");   
var countries = document.querySelectorAll(".epgtvm_structure-container ol a");

这里是完整的功能,但是在IOS上不起作用

function mobileCountries() {

//create the select element for the dropdown list before the ol
var selectList = document.createElement("select");
selectList.setAttribute('data-selectconverted', 'true');
listSelect.appendChild(selectList);


var countries = document.querySelectorAll(".epgtvm_structure-container ol a");
var countryOrder = [];

//arrange country name and url in alphabetical order
countries.forEach(function(val) { //forEach for countries in <option>
countryOrder.push({
'name': val.innerText,
'url': val.href
});
countryOrder.sort(dynamicSort("name"));
// return this;
});

//Create the option elements for the dropdown
countryOrder.forEach(function(val) {
var optionElement = document.createElement("option");
//optionElement.innerHTML += val.name;
optionElement.innerText = val.name;
optionElement.label = val.name;
optionElement.value = val.url;
selectList.appendChild(optionElement);
});

selectList.setAttribute('onblur', 'window.location = this.value;'); //onchange submit for the select
}
}
//DOM CONTENT READY
window.addEventListener("load", mobileCountries);

所以代码获取所有链接并在选择标签内创建选项元素,它在任何地方都可以工作,但在 IOS 中,有人知道它可能是什么吗?

谢谢

最佳答案

尝试使用 Option 构造函数:

  // Create the option elements for the dropdown
countryOrder.forEach(function(val) {
selectList.appendChild(new Option(val.name, val.url));
});

关于javascript - 通过 javascript 为移动设备转换为选择选项的列表,不适用于 IOS 移动浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56152735/

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