
正文
jquery渲染option,jquery渲染列表并且点击事件传入参数
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
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" /spanhtml.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=Homec=ClassLista=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'); } }) }
相关问答
Q1: jquery怎么添加option的选项
直接用append方法就可以了,如:$("#selectId").append("option value='"+value+"'Test/option");
Q2: 调用接口渲染两个select联动用jquery怎么实现
这个是三级联动,值是预设,你换乘带参数的动态接口数据即可
script language="JavaScript" type="text/javascript"
function createCode()
{
//数组赋值
var varname = new Array(4);
varname[0] = "请选择";
varname[1] = "红色";
varname[2] = "黄色";
varname[3] = "蓝色";
//下拉框赋值
for(var i=0;i4;i++)
{
document.getElementById('xlk1').options[i] = new Option(varname[i],i);
}
copy();
}
//复制下拉框一给下拉框二
function copy()
{
for(i=0;idocument.getElementById("xlk1").options.length;i++)
{
document.getElementById('xlk2').options[i] = new Option(document.getElementById("xlk1").options[i].text,i)
}
copytwo();
}
//复制下拉框一给下拉框二
function copytwo()
{
for(i=0;idocument.getElementById("xlk2").options.length;i++)
{
document.getElementById('xlk3').options[i] = new Option(document.getElementById("xlk2").options[i].text,i)
}
}
function onChange1()
{
//获取下拉框1的选中项
var strid=document.getElementById("xlk1").value;
//获取选中项的内容
//var strtxt=document.getElementById("xlk1").options[window.document.getElementById("xlk1").selectedIndex].text;
//获取指定ID下拉框的项总数
//var strnub=document.getElementById("xlk1").options.length;
copy();
if(strid != 0)
{
document.getElementById("xlk2").options.remove(strid);
document.getElementById("xlk3").options.remove(strid);
}
document.getElementById("textfield").value=strid+strtxt+strnub;
}
function onChange2()
{
//获取下拉框1的选中项
var strid2=document.getElementById("xlk2").selectedIndex;
//获取选中项的内容
var strtxt2=document.getElementById("xlk2").options[window.document.getElementById("xlk2").selectedIndex].text;
//获取指定ID下拉框的项总数
var strnub2=document.getElementById("xlk2").options.length;
copytwo();
if(strid2 != 0)
{
document.getElementById("xlk3").options.remove(strid2);
}
}
/script
body onLoad="createCode()"
form id="form1" name="form1" method="post" action=""
select name="xlk1" id="xlk1" onChange="onChange1()"/select
select name="xlk2" id="xlk2" onChange="onChange2()"/select
select name="xlk3" id="xlk3"/select
/form
jquery渲染option的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于jquery渲染列表并且点击事件传入参数、jquery渲染option的信息别忘了在本站进行查找喔。







