jQuery UI 对话框 - 从表 DIV 中抓取文本并显示 - 仅在第一次单击时发生
我试图将表格单元格中的一些文本动态地放入 jQuery UI 对话框中,从表格中的链接触发(每行一个)。它对每个链接都有效一次,但此后就停止了。
这是我的 Javascript:
$(function() {
$( ".abstractlink" ).click(function() {
$( $(this).parent().find('.abstract') ).dialog({
modal: true,
autoOpen: true,
height: "auto",
width: "600",
draggable: "true",
title: "Project abstract",
resizable: "false"
});
});
});
问题是(我认为)每次单击链接时我都会重新初始化对话框。问题是,我需要更改每次单击链接时要显示的 DIV(因此在父 (TR) 元素中找到具有“abstract”类的元素。
这是表代码的相关部分:
<tr>
<td><a href="javascript:;" class="abstractlink">View</a><div class="abstract" id="project_abstract_3">Project 3 abstract. Lorem ipsum.</div></td>
</tr>
我有强烈的感觉这不是解决这个问题的一种非常优雅的方法,但由于我对 jQuery 还很陌生,所以我很高兴到目前为止我得到了
任何建议!
I'm trying to get some text in a table cell into a jQuery UI dialog dynamically, firing from a link in the table (one for each row). It works for each link once, but thereafter it stops.
Here's my Javascript:
$(function() {
$( ".abstractlink" ).click(function() {
$( $(this).parent().find('.abstract') ).dialog({
modal: true,
autoOpen: true,
height: "auto",
width: "600",
draggable: "true",
title: "Project abstract",
resizable: "false"
});
});
});
The problem is (I think) that I'm re-initialising the dialog each time a link is clicked. Trouble is, I need to change the DIV which is to be displayed each time a link is clicked (hence finding the element with the class 'abstract' in the parent (TR) element.
Here's the relevant part of the table's code:
<tr>
<td><a href="javascript:;" class="abstractlink">View</a><div class="abstract" id="project_abstract_3">Project 3 abstract. Lorem ipsum.</div></td>
</tr>
I have a strong feeling that this isn't a very elegant way of solving this problem, but as I'm still new to jQuery I am so I was glad I got this far.
Any suggestions much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
文档 说:
更多信息此处。
编辑:警告,未经测试的代码:
您不是在创建一个对话框,而是为每个抽象 div 创建一个对话框。然后,您告诉他们在需要时打开。
The Docs say:
More info here.
Edit: Warning, untested code:
You're not creating one dialog box, you're creating a dialog box for every abstract div. Then, you're telling them to open when needed.
看起来你只想要类似的东西:
Looks like you just want something like: