我怎样才能把一个变量formulaire选项在javascript
问题描述:
我想,以填补JavaScript中的选择列表的:我怎样才能把一个变量formulaire选项在javascript
for (i=0; i<10; i++)
{
formulaire.choixType[i].options.length= 10;
formulaire.choixType[i].options[i].value =i;
formulaire.choixType[i].options[i].text =i;
}
我有10个选择列表的(K从0到9):
<div>
<select name="choixType[k]" id="choixType" >
<option value="" selected="selected">---choose-</option>
</select>
</button>
</div>
我怎么能做到这一点,谢谢你帮
答
我已经在这里创造的为例:https://jsfiddle.net/xctty5bd/1/
// get select element with id 'choixType'
var select = document.getElementById('choixType');
for (var i = 0; i < 10; i++) {
// first you create the element <option></option>
var option = document.createElement('option');
// then you add value and text
option.value = i;
option.text = i;
// and then you put option at the end of your select
select.appendChild(option);
}
谢谢你的帮助,但我有更多的下拉列表,我有k dropdownlist和k是变种, – oaninat
只需使用一个简单的循环来填充每个选择,现在将很容易,因为你知道如何填写一个。 – Gatsbill
耶谢谢你:) – oaninat