将 .click() 添加到动态创建的选项卡
我正在尝试将 .click() 添加到动态添加的选项卡中。
到目前为止的代码:
var newtabid = "#privChatArea" + chatmessage.SenderID;
$("#tabs").tabs("add", newtabid, "<span style=\"color: red;\">" + chatmessage.SenderNick + "</span>");
我似乎不知道如何引用 Tab 按钮,因为我实际上给出 ID 的唯一元素是
有人知道该怎么做吗?
编辑:澄清
选项卡包括
<div id="tabs">
<ul id="tabscontainer">
<li><a href="#chatroom1" id="_chatroom1"><span>test1</span></a></li>
<li><a href="#chatroom2" id="_chatroom2"><span>test2</span></a></li>
<li><a href="#chatroom3" id="_chatroom3"><span>test3</span></a></li>
</ul>
<div id="chatroom1" style="max-height: 400px; height: 400px; width: 100%; overflow-y: scroll;">
</div>
<div id="chatroom2" style="max-height: 400px; height: 400px; width: 100%; overflow-y: scroll;">
</div>
<div id="chatroom3" style="max-height: 400px; height: 400px; width: 100%; overflow-y: scroll;">
</div>
我无法获取对创建选项卡时创建的 id 的引用。使用 .tabs("add") 时未指定此 ID
干杯!
I'm attempting to add a .click() to a tab that I add dynamically.
Code so far:
var newtabid = "#privChatArea" + chatmessage.SenderID;
$("#tabs").tabs("add", newtabid, "<span style=\"color: red;\">" + chatmessage.SenderNick + "</span>");
I can't seem to figure out how to reference the Tab-button, as the only element I am actually giving an ID is the <div id="privChatArea[id]"></div>
Anyone know how to do this?
EDIT: Clarification
The tabs consist of
<div id="tabs">
<ul id="tabscontainer">
<li><a href="#chatroom1" id="_chatroom1"><span>test1</span></a></li>
<li><a href="#chatroom2" id="_chatroom2"><span>test2</span></a></li>
<li><a href="#chatroom3" id="_chatroom3"><span>test3</span></a></li>
</ul>
<div id="chatroom1" style="max-height: 400px; height: 400px; width: 100%; overflow-y: scroll;">
</div>
<div id="chatroom2" style="max-height: 400px; height: 400px; width: 100%; overflow-y: scroll;">
</div>
<div id="chatroom3" style="max-height: 400px; height: 400px; width: 100%; overflow-y: scroll;">
</div>
I'm having trouble getting a reference to the id of the which is created when the tab is also created. This ID is not specified when using the .tabs("add")
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用“live”为动态创建的元素绑定事件。您可以为所有选项卡选择一种选择器(可能是类等),并将事件绑定到 $(document).ready()
http://docs.jquery.com/Events/live
编辑:再次阅读您的问题后,我认为我应该澄清一下。您应该将实时事件绑定到您正在创建的“跨度”
use "live" to bind events for dynamically created elements. You can choose one kind of selectors (may be a class etc) for all your tabs and bind events with live on your $(document).ready()
http://docs.jquery.com/Events/live
Edit: After reading your question again, thought I should clarify. You should bind the live event to the "span" which you are creating
应该很简单:
Should be as simple as: