mui.ready(function(){
// load
reload();
});
var reload = function() {
var content = document.getElementById('content');
var ul = document.getElementById('content_ul');
var lis = ul.getElementsByTagName('li');
console.log(lis.length);
var len = lis.length;
for (var i = 0; i < len; i++) {
console.log('remove' + i);
ul.removeChild(lis[0]);
console.log('remove' + i + 1);
}
console.log(localStorage.getItem('loginName'));
mui.ajax('URL', {
data: {
userName: localStorage.getItem('loginName')
},
dataType: 'json',
type: 'post',
timeout: 10000,
success: function(data) {
console.log('success!!!!!!');
console.log(data);
var projects = data.projects;
if (projects == 'undefined' || projects == 'null') {
return;
}
projects = projects.substring(1, projects.length - 1);
var array = projects.split("},");
for (var i = 0; i < array.length; i++) {
var str = array[i];
if (str.substr(str.length - 1, str.length) != '}') {
str += '}';
}
var project = JSON.parse(str);
var li = document.createElement('li');
li.setAttribute("id", project.id);
li.setAttribute("class", "mui-table-view-cell mui-media");
var a = document.createElement('a');
// a.href="project.html?project="+project;
a.href=mui.openWindow({
url:"project.html",
id:"project.html",
extras:{project:project}
});
if (project.img != null && project.img != "") {
var img = document.createElement('img');
img.setAttribute("class", "mui-media-object mui-pull-right");
var imgPath = project.img.substring(13, project.img.length);
imgPath = serverAddr + imgPath;
img.src = imgPath;
a.appendChild(img);
}
var div = document.createElement('div');
div.setAttribute("class", "mui-media-body");
div.innerHTML = project.name;
var p = document.createElement('p');
p.setAttribute("class", "mui-ellipsis");
p.innerHTML = project.desc;
div.appendChild(p);
a.appendChild(div);
li.appendChild(a);
ul.appendChild(li);
div.addEventListener("click",showDetail(project.id),false);
}
},
error: function(xhr, type, errorThrown) {
console.log('刷新失败' + type);
alert('刷新失败!');
}
});
}
上面是源码
问题如下:每次打开页面会自动跳转到a.href的目标页面而且是每循环一次跳转一次 如我加载里有5条数据那么会打开5次目标页面 是自动打开 本想实现点击li 跳转到相应页面的 请问这是什么原因
0 个回复