当我在 html 表中的 td 内单击时,我想弹出一个对话框。这可能吗 ?
问问题
1096 次
1 回答
3
TD作为代理...
如果你有一个链接,你可以这样做:
$("td").click(function(){
$("a[rel='facebox']", this).trigger("click");
});
当然,稍微修改该代码,您可以通过单击页面上的几乎任何其他内容来为任何链接调用 facebox。基本上,该td
元素充当您的代理。如果您单击它,它会触发对能够打开 Facebook 的链接的单击。
没有链接?没问题...
如果您没有要点击的链接,您可以创建一个苍蝇,触发点击,然后将其删除。
$("td").click(function(e){
$("<a>") // create our link
.click(function(e){e.stopPropagation()}) // prevent bubbling
.attr({ // set its attributes
'href':'/css/style.css?'+$(this).text(), // append td vals
'rel':'facebox' // make it facebox-eligible
})
.appendTo(this) // append it to the td
.facebox() // tie it to facebox
.click() // click it
.remove(); // remove it
});
所以假设我们从以下开始:
<td>52</td>
我们将有一个 iframe 弹出窗口指向:/css/style.css?52
。
于 2010-02-22T03:54:41.520 回答