json数据 jquery 如何给 select name="ddlProvince" id="ddlProvince" 赋值
json格式如下:{"provlist":["安徽","北京","福建","甘肃","广东","广西","广西\t","贵州","海南","河北","河南","黑龙江",...
json 格式如下:
{"provlist":["安徽","北京","福建","甘肃","广东","广西","广西\t","贵州","海南","河北","河
南","黑龙江","湖北","湖南","吉林","江苏","江西","辽宁","内蒙","内蒙古","宁夏","
青海","山东","山西","陕西","上海","四川","天津","新疆","云南","浙江","重庆"]}
如何给
<select name="ddlProvince" id="ddlProvince">
</select>
赋值 展开
{"provlist":["安徽","北京","福建","甘肃","广东","广西","广西\t","贵州","海南","河北","河
南","黑龙江","湖北","湖南","吉林","江苏","江西","辽宁","内蒙","内蒙古","宁夏","
青海","山东","山西","陕西","上海","四川","天津","新疆","云南","浙江","重庆"]}
如何给
<select name="ddlProvince" id="ddlProvince">
</select>
赋值 展开
2015-09-07 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
1、先判断返回的json数据的格式。
2、然后用jquery将值取出并拼接成字符串。
3、插入到html对象中。
下面是具体的实现过程:
<select id="select"></select>
<script type="text/javascript">
html= "";
str = {"prolist":['安徽','北京']};//josn对象.
$.each(str.prolist,function(a,b){//直接取出json的prolist做each循环.
html += "<option>"+b+"</option>";//拼接字符串.
});
$("#select").html(html);//将拼接好的字符串插入到id为select的 select对象中.
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询