js判断点击了哪个循环生成DIV

zhuyouyong 2012-03-02 02:59:44

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不知道该怎么写!
...全文
238 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhuyouyong 2012-03-09
  • 打赏
  • 举报
回复
对不起,大家了,最近太忙,忘记结贴了,大家说的很对,解决方法,正如楼上所说!
lsw645645645 2012-03-03
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhuyouyong 的回复:]
如果我现在想根据这个url访问div元素可以吗?
[/Quote]
$(div[href=url])
zhuyouyong 2012-03-03
  • 打赏
  • 举报
回复
两位说的都很对,
<div class='space-selectItem-two' url='"+departmentSpace_url+"' style='width:100%;height:100%;line-height:2;'onclick(function(url))>
这样写$(this).attr("url")就可以得到

如果我现在想根据这个url访问div元素可以吗?
oldhen123 2012-03-02
  • 打赏
  • 举报
回复
用jquery这样写?
$("div.space-selectItem-two").click(function(){
url=$(this).find("span a.select").attr("href");
});
Acesidonu 2012-03-02
  • 打赏
  • 举报
回复
注册点击div的函数,当发生点击时查询获得当前div中的对应的departmentSpace_url不就得了

87,989

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧