时间:2021-01-22 12:25:57 | 栏目:jquery | 点击:次
如下所示:
var provinces = res.res; var html = []; var option_select='<option value="" >请选择</option>'; var tpl = '<option value="{1}" data-id="{1}" data-name="{0}">{0}</option>'; html.push(option_select); $.each(provinces, function (i, n) { <span style="white-space:pre"> </span>html.push(tpl.format(n.name, n.id)); }); //alert(html.join()); $('#class').html(html.join(''));
function getXueke() { var gradeId = $('#grade_id').val(); if (gradeId == '') { $('#textbook_id').html('<option value="">-选择-</option>'); return; } $.get('index.php?m=Home&c=ClassList&a=getgradesandCourse', { 'grade_id': gradeId }, function (res) { var options = []; $.each(res, function (index, item) { options.push('<option value="{0}">{1}</option>'.format(item.id, item.course_name)); }); if (options.length > 0) { $('#textbook_id').html(options.join('')); } else { $('#textbook_id').html('<option value="">-请选择-</option>'); } }) }