gpt4 book ai didi

javascript - 自动填充选项标签不工作 javascript

转载 作者:行者123 更新时间:2023-11-28 04:33:07 25 4
gpt4 key购买 nike

我试图在 select - option 标签中填充数字。但是我的脚本只在一个选择标签中填充数字

HTML:

 <div class="form_row">
<label>Week Num</label>
<select class="form_select1" id="weeknum"></select>
<b class="bold1">&nbsp TO &nbsp</b>
<select class="form_select1" id="weeknum1"></select>
</div>

Javascript:

 <script>
var select = document.getElementById("weeknum");
var select1 = document.getElementById("weeknum1");
for (var i = 52; i >= 1; i--) {
var option = document.createElement('option');
option.text = option.value = i;
select.add(option, 0);
select1.add(option, 0);
}
</script>

enter image description here

我该如何实现?

最佳答案

您只能将一个元素添加到父节点一次,因此您需要创建另一个选项元素:

var select = document.getElementById("weeknum");
var select1 = document.getElementById("weeknum1");
for (var i = 52; i >= 1; i--) {
var option = document.createElement('option');
option.text = option.value = i;
var option1 = document.createElement('option');
option1.text = option1.value = i;
select.add(option, 0);
select1.add(option1, 0);
}

这是 JSFIddle .

关于javascript - 自动填充选项标签不工作 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27638828/

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