示例:
JS代码:
<script>
var gSelectID = ["1521","yuki",'拉克丝'];
for (var i in gSelectID) {
var selectID = document.getElementById("selectID");
var option = document.createElement("option");// 创建option元素
option.appendChild(document.createTextNode(gSelectID[i]));
option.setAttribute("value", gSelectID[i]);
selectID.appendChild(option);
}
</script>
html代码:
<div id="selectIdBox">
<select id="selectID"></select>
</div>
插曲:当数组中的元素没有加引号,并且数据多的时候,在 PyCharm中采取正则表达式
转载:解决方法
https://blog.csdn.net/weixin_41665637/article/details/116267573
这篇博客介绍了如何使用JavaScript将数组内容填充到HTML select元素的option中,提供了一个示例代码,并提到了在PyCharm中处理大量数据时的正则表达式技巧,同时分享了一个详细的解决方案链接。

9954

被折叠的 条评论
为什么被折叠?



