dealPictureInfo: function(json) {
$.each(json.data, function(i, item) {
// “\”为转义字符, /g代表全局匹配
var reg = /http:\/\/public-api.nj.pla.xxx.org/g;
// 将url中的http://public-api.nj.pla.xxx.org 替换为https://m.xxx.com
var imageUrl = item.url.replace(reg, "https://m.xxx.com");
//字符串转数组,转换采用(?!/—)分割
var temp = imageUrl.split(/\/(?!\/)/); // //(?!/)/
//把最后一个元素去掉后缀
temp[temp.length - 1] = temp[temp.length - 1].replace( "_w800_h400_c1_t0.", ".");
//吧temp数组拼装成字符串,alt代表图片不存在时显示的数字描述,并在图片上添加点击监控,
imgLi = $('<a><img src="' + temp.join("/") + '" alt="" /></a>').click(function() {
if (item.linkUrl) {
//item.linkUrl中匹配的到“http”,返回源数据,配置不到,返回null,
item.linkUrl.match("http") ? null : (item.linkUrl = "https://" + item.linkUrl);
//打开新窗口
window.open(item.linkUrl);
} else {
return false;
}
});
//在#sildy后追加图片
$("#slidy").append(imgLi);
});
},