使用JQuery2.0.0动态添加标签
$(function() {
// 请求json数组
$.ajax({
type: "POST", //请求方式
url: "https://api.jisuapi.com/area/province?appkey=***", //地址,就是json文件的请求路径
dataType: "jsonp", //数据类型可以为 text xml json script jsonp
success: function(result) {
addSheng(result.result)
}
});
});
//在#dongdong-box中添加标签
function addSheng(arr2) {
// var arr2 = [
// ['https://news.edu.360.cn/', '教育'],
// ['b', 'bb'],
// ['c', 'cc']
// ];
$.each(arr2, function(i, item) {
console.log(i + "====" + item.name);
// 选中id:the_province,使用append方法在标签<div>后添加拼接标签,</div>
$('#the_province').append($('<a href="' + item.name + '">' + item.name + '</a>'));
})
}
