我想加载数字1到20的下拉列表,我有一个javascript代码来执行此操作。但不确定如何在下拉列表中调用此函数。
$(document).ready(function(){
quantitydropdown();
})
function quantitydropdown()
{
// Get reference to drop down
var ddl = document.getElementById('quantitydropdownid');
for (var i = 1; i < 21; i++) {
var theOption = document.createElement("option");
theOption.text = i;
theOption.value = i;
// If it is the first option, make it be selected
i === 1 ? theOption.selected = "selected" : "";
ddl.options[i] = theOption;
}
}
#quantitydropdownid { width:200px; }
#quantitydropdownid option:empty
{
display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label for="quantitydropdown">Quantity</label>
<select id="quantitydropdownid" runat="server"></select>
所以我不确定如何将这个javascript函数调用到下拉列表中。需要帮助!!