for(i=0;i<jsonArr.length;i++){

var photo = jsonArr[i].photo;
var photourl;
if(typeof(photo) == "undefined")
{
var photourl = "http://172.16.104.13:8081/static/images/avatar_64_64.png";
}
else{
photourl = TS.app.utils.getAvatarURL(photo);
}
var departmentSpace_url = TS.app.utils.getSystemURL("department/"+jsonArr[i].id);
selectItem +="<div class='space-selectItem-two'id='space-"+i+"' style='width:100%;height:100%;line-height:2;'>"
       +"<span style='width:24px;height:24px; margin-left: 8px;'><image style='width:24px;height:24px;' src='"+photourl+"'/>" +
       "</span>"
       +"<span class='space-head-"+i+"' style='display:inline-block;'>"
       +"<a hidefocus='true' href='"+departmentSpace_url+"' class='select'>"
       +jsonArr[i].name
       +"</a>"+"</span>"+"</div>";
通过for循环生成了很多的div和departmentSpace_url想获取,点击的那个div对应的departmentSpace_url不知道该怎么写!

解决方案 »

  1.   

    注册点击div的函数,当发生点击时查询获得当前div中的对应的departmentSpace_url不就得了
      

  2.   

    用jquery这样写?
    $("div.space-selectItem-two").click(function(){
       url=$(this).find("span a.select").attr("href");
    });
      

  3.   

    两位说的都很对,<div class='space-selectItem-two' url='"+departmentSpace_url+"' style='width:100%;height:100%;line-height:2;'onclick(function(url))>这样写$(this).attr("url")就可以得到如果我现在想根据这个url访问div元素可以吗?