jquery結果集遍歷【新版】
$.getJSON(shopInfoUrl, function(data) {
if (data.success) {
// 若訪問成功,則依據後臺傳遞過來的店鋪信息爲表單元素賦值
var tempAreaHtml = '';
// 初始化區域列表,遍歷返回結果集
data.areaList.map(function(item, index) {
tempAreaHtml += '<option data-id="' + item.areaId + '">'
+ item.areaName + '</option>';
});
$('#area').html(tempAreaHtml);
// 給店鋪選定原先的所屬的區域
$("#area option[data-id='" + shop.area.areaId + "']").attr(
"selected", "selected");
}
});
}
快速遍歷select標籤,獲取選中值!
$('#shop-category').find('option').not(function() {
return !this.selected;
}).data('id')
獲取上傳的圖片文件流
var shopImg = $('#shop-img')[0].files[0];
生成表單對象,用於接收參數並傳遞給後臺
var formData = new FormData();
// 添加圖片流進表單對象裏
formData.append('shopImg', shopImg);
// 將shop json對象轉成字符流保存至表單對象key爲shopStr的的鍵值對裏
formData.append('shopStr', JSON.stringify(shop));