html(标准html语法)
<select id='sizeofgame'></select>
script /(我创建了一个循环)
var select='';
for (var i = 1; i <= 100; i++)
{
select += '<option value='i'>'i'</option>'
}
$('#sizeofgame').html(select)
我感到困惑,请帮我解决正确的代码
答案 0 :(得分:3)
这是jsFiddle http://jsfiddle.net/tnzyz/
完全按照你想要的纯javascript:)
JavaScript代码
var select = document.getElementById("sizeofgame");
for(var i = 1; i <= 100; i++) {
var el = document.createElement("option");
el.textContent = i;
el.value = i;
select.appendChild(el);
}
答案 1 :(得分:1)
你可以这样试试,
HTML:
<select id="numDD">
</select>
jQuery:
$(document).ready(function(){
var i = 0;
var result = "";
for(i = 1; i <= 100; i++){
result += "<option value=" + i + ">"+ i +"</option>";
}
$("#numDD").html(result);
});