使用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>'));
})
}
