我使用的是jQueryUI的对话框小部件。现在,链接是通过使用jQuery+AJAX从SQL数据库获取的,这就是我使用"live“的原因。
$(function() {
var $dialog = $('#report')
.dialog({
autoOpen: false,
resizable: false,
modal: true,
height: 410,
width: 350,
draggable: true
})
//store reference to placeholders
$uid = $('#reportUniqueId');
$('.reportopen').live("click", function (e) {
$dialog.dialog('open');
var $uid = $(this).attr('id');
e.preventDefault();
});
});
我的问题是,如何将触发对话框小部件的链接的id
传递给对话框本身?链接设置如下:
<td align="left" width="12%">
<span id="notes">
[<a href="javascript:void(0)" class="reportopen" id="<?=$reportId;?>">Spam</a>]
</span>
</td>
对话框的设置如下所示:
<div id="report" title="Inquire now">
HAHAHAHAHA
<span id="reportUniqueId"></span>
</div>
我希望在对话框的<span id="reportUniqueId"></span>
部分传递并生成id
。
有什么想法吗?
发布于 2012-09-03 23:37:00
$(".reportopen").click(function(){
var monId= $(this).attr("id");
$("#reportUniqueId").text(monId);
$dialog.dialog('open');
});
发布于 2012-10-18 23:59:57
当您使用jQuery click
处理程序时,它会将一个event
传递给函数,您在参数中将该函数命名为e
。
如果您想使用console.log
,可以检查这个对象,但重要的是e.target
引用了触发单击事件的DOM元素。我确信您可以先使用jQuery将其转换为包装的集合/元素,即:
$(e.target)
然后,您可以使用其他注释中的技术获取其ID,即:
$(e.target).attr('id')
请让我知道这是否有效。
https://stackoverflow.com/questions/12250436
复制相似问题