如何将getProjectssexy(1)更改为i数字(取决于tmpArray.length) 对于每个元素我需要getProjectssexy(0),getProjectssexy(1),等等
$('allarray', data).each(function(){
tmpArray = $('array', this).toArray();
var table = document.getElementById("tleft");
table.innerHTML = "";
for(i =0; i<tmpArray.length; i++) {
table.innerHTML += "<div class='two'>" +
"<a href='#' onclick='getProjectssexy(1 - need to change i for every loop)'>" +
tmpArray[i].getAttribute("id") + "</a>" +"</div>" + "</br>";
}
});
答案 0 :(得分:0)
你必须把它存放在元素的某个地方。您可以使用html5 data-*属性来存储它,并使用jQuery .data()来检索它。
$('allarray', data).each(function(){
tmpArray = $('array', this).toArray();
var table = document.getElementById("tleft");
table.innerHTML = "";
for(i =0; i<tmpArray.length; i++) {
table.innerHTML += "<div class='two'>" +
"<a href='#' data-i='" + i + "' onclick='getProjectssexy(this)'>" +
tmpArray[i].getAttribute("id") + "</a>" +"</div>" + "</br>";
}
});
function getProjectssexy(elem) {
var i = $(elem).data('i');
....
}
答案 1 :(得分:0)
它的基本解决方案
$('allarray', data).each(function(){
tmpArray = $('array', this).toArray();
var table = document.getElementById("tleft");
table.innerHTML = "";
for(i =0; i<tmpArray.length; i++) {
table.innerHTML += "<div class='two'>" +
"<a href='#' onclick='getProjectssexy("+i+")'>" +
tmpArray[i].getAttribute("id") + "</a>" +"</div>" + "</br>";
}
});