点击无效时获取列表项的自动生成ID

时间:2016-11-09 10:13:53

标签: javascript jquery html

我试图在点击事件中获取li的ID,但它不起作用,

 function dialougeboxclick(){
            alert('i am call here');
            console.log($(this));
            alert("attributes are"+$(this).attr());//undefined
            alert("id is "+$(this).attr("id"));//undefined
            alert("event id"+event.target.id);//empty
            $('#').removeClass('box-li').addClass('box-li selected');
        }

//动态填充li

$("#roster").append(
                    //uniquely identify it id="' + hashjid + '">
                '<li  class="box-li" onclick=dialougeboxclick() id="' + hashjid + '">' +
                                '<div class="ChatListContainer">'+
                                    '<div class="chatNameLeft">'+
                                        '<div><img src="../res/Chat/images/larry.png"></div>'+
                                        '<div id="' + jid + '" class="status">online</div>' +
                                    '</div>'+

                                    '<div class="chatDetailsRight inline-right">'+
                                        '<h4 class="mg-0 NameOfParticipant">'+name+'</h4>'+
                                        '<p class="mg-0 DesignationOfParticipant">CEO</p>'+
                '<p class="MessageOneLiner"><span class="readStatus Dblue">//</span>Sure, let me email it to you</p>'+

                                    '</div>'+
                                    '<span class="TimeStamp TimeStampBroadCastList">14:25 am</span>'+
                                '</div>'+
                            '</li>'
                          );

问题是什么?下面是hirarchy

  <div class="cont-box scroll">
                        <ul id="roster">
</ul>
</div>

0 个答案:

没有答案