日期:2014-05-16 浏览次数:20479 次
var PathSet = $(this).attr('p'); var folderPathSize = PathSet.substring(1, PathSet.length).split('/'); var folderPath = PathSet; var arrayPath = new Array(); var num = 0; if(folderPathSize.length > 1) { for(j = 0; j < folderPathSize.length; j++) { if(j != folderPathSize.length - 1) { folderPath = folderPath.substring(0, folderPath.lastIndexOf('/')); arrayPath[num] = folderPath; num = num + 1; } } arrayPath.reverse(); } arrayPath[num] = PathSet; for(k = 0; k < arrayPath.length; k++) { alert(arrayPath[k]); //正常输出 var PathLink = $("<a>"); PathLink.append(arrayPath[k].substring(arrayPath[k].lastIndexOf('/') + 1)); PathLink.bind('click', function() { alert(arrayPath[k]); //输出undefined //$(".leftBlock").remove(); //******* 需要处理的地方 }); $('#track').append(" -> "); $('#track').append(PathLink); } });
//这样试试 for (k = 0; k < arrayPath.length; k++) { alert(arrayPath[k]); //正常输出 var PathLink = $("<a>"); PathLink.append(arrayPath[k].substring(arrayPath[k].lastIndexOf('/') + 1)); PathLink.tmp = arrayPath[k]; //定义个属性,值设为array[k] PathLink.bind('click', function() { alert(this.tmp); }); $('#track').append(" -> "); $('#track').append(PathLink); }
------解决方案--------------------
for(k = 0; k < arrayPath.length; k++) { alert(arrayPath[k]); //正常输出 var PathLink = $("<a>"); PathLink.append(arrayPath[k].substring(arrayPath[k].lastIndexOf('/') + 1)); PathLink.bind('click', function([color=#FF0000]此处需要传参或者将这个click方法写成闭包[/color]) { alert(arrayPath[k]); //输出undefined //$(".leftBlock").remove(); //******* 需要处理的地方 }); $('#track').append(" -> "); $('#track').append(PathLink); }
------解决方案--------------------