jquery ajax加载数据前台渲染方式 不用for遍历的方法
如下所示:
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>'); } }) }
相关推荐
专注前端开发 2020-10-21
苏康申 2020-11-13
vitasfly 2020-11-12
oraclemch 2020-11-06
liuyang000 2020-09-25
FellowYourHeart 2020-10-05
赵继业 2020-08-17
whyname 2020-08-16
Seandba 2020-08-16
dbasunny 2020-08-16
拼命工作好好玩 2020-08-15
langyue 2020-08-15
写程序的赵童鞋 2020-08-03
Accpcjg 2020-08-02
tydldd 2020-07-30
好记忆也需烂 2020-07-28
jianghero 2020-07-28