我正在使用jQueryUI的对话框小部件。现在,使用jQuery+AAJAX从SQL数据库中获取链接,这就是我使用"实时"的原因
$(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
。
知道吗?
$(".reportopen").click(function(){
var monId= $(this).attr("id");
$("#reportUniqueId").text(monId);
$dialog.dialog('open');
});
当您使用jQuery click
处理程序时,它会将一个event
传递给函数,您在参数中将其命名为e
。
如果您想使用console.log
,您可以检查这个对象,但重要的是e.target
引用了触发点击事件的DOM元素。我确信您可以使用jQuery首先将其转换为包装的集合/元素,即:
$(e.target)
然后你可以使用其他评论中的技术来获得它的ID,即:
$(e.target).attr('id')
请告诉我这是否有效。