每当用户按下文本框中的任意键时,我想访问父div的data-user-id ...
类面板只是一个聊天窗口,其中包含动态分配给他的接收者ID。
HTML:
<div class="chat-window-container">
<div class="panel panel-default container" data-user-id="a4c2c119-623e-436d-a750-a521012953fb" id="chat-0001" style="display: block;">
<div class="panel-heading" data-toggle="chat-collapse" data-target="#chat-bill">
<a href="#" class="close"><i class="fa fa-times"></i></a>
<a href="#">
<span class="pull-left">
<img src="../../Images/bluemanmxxl.png" width="40">
</span>
<span class="contact-name">ser fdf</span>
</a>
</div>
<div class="panel-body" id="chat-bill" style="height:300px;overflow-y:scroll">
<div class="panel-body" id="chat-bill">
<div class="media">
<div id="chatContainer">
</div>
</div>
<input type="text" id="msg" class="form-control ChatText" onkeydown="return sendfunction(event)" placeholder="Type message...">
</div>
</div>
</div>
<div class="panel panel-default container" data-user-id="7c344592-f323-4baa-869c-a5210129041e" id="chat-0002" style="display: block;">
<div class="panel-heading" data-toggle="chat-collapse" data-target="#chat-bill">
<a href="#" class="close"><i class="fa fa-times"></i></a>
<a href="#">
<span class="pull-left">
<img src="../../Images/bluemanmxxl.png" width="40">
</span>
<span class="contact-name">ABC sdsd</span>
</a>
</div>
<div class="media">
<div id="chatContainer">
</div>
</div>
<input type="text" id="msg" class="form-control ChatText" onkeydown="return sendfunction(event)" placeholder="Type message...">
</div>
</div>
JS:
function sendfunction(e) {
var keynum;
if (window.event) {
keynum = e.keyCode;
}
if (keynum == 13) {
strChatText = $("#msg").val();
if (strChatText != '') {
var strGroupName = gname;
if (typeof strGroupName !== 'undefined' && strGroupName !== false)
chat.server.send(strChatText, gname, '@ViewBag.LoginUserId', a);
$("#msg").val('');
}
return false;
}
}
答案 0 :(得分:1)
答案 1 :(得分:0)
$(e.target)。家长(&#39; .container&#39)。ATTR(&#39;数据用户ID&#39)