var myOptions_bench = {
1 : '1',
2 : '2',
3 : '3'}
$.each(myOptions_bench, function(val, text) {
$('#test').append(
$('<option></option>').val(val).html(text)
);
在这里,我想加载我自己的详细信息。(有时 1 到 3 有时 5 到 50(。动态我想更改选项。for 循环在这里不起作用。
请做需要的。谢谢
尝试这样的事情
var myOptions_bench = {
1 : '1',
2 : '2',
3 : '3'};
//remove current options
$('#test').html('');
//add new options
for(var i = 1;i < myOptions_bench.length+1 ;i++){
$('#test').append($('<option></option>').val(i).html(i));
}
使用循环
尝试此操作for
。您可以根据需要设置循环的开始和结束。
$('#test').empty();//Clear the list
for(var i = 1;i < 50;i++){
$('#test').append($('<option></option>').val(i).html(i));
}
$.ajax({
url: "mydetails.php",
success: function(data){
//process your data to var myOptions_bench
}
});
$.ajax @jquery.com
你有一些语法错误等。
尝试:
myOptions_bench = {
1: '1',
2: '2',
3: '3'
}
$.each(myOptions_bench, function(val, text) {
$('#test').append('<option value="' + val + '">' + text + '</option>');
});
小提琴:http://jsfiddle.net/MNk3a/