我有一个对话窗口,有一个2比2的表格。而不是单击按钮,我希望能够单击任何单元格,它会在警告框中返回值/文本。但是,我不确定我将以下alert($(event.target).text());
放入哪里?
$("#dialog-message").dialog({
modal: true,
draggable: false,
resizable: false,
position: ['center', 'top'],
show: 'blind',
hide: 'blind',
width: 400,
dialogClass: 'ui-dialog-osx',
buttons: {
"I've read and understand this": function() {
$(this).dialog("close");
}
}
});
这是代码 Fiddle
答案 0 :(得分:0)
如果您需要单元格文本,请将点击事件绑定到th,td
(根据您的标记)。
$("#dialog-message th,td").click(function(event){
alert($(event.target).text()); //$(this).text() would work too.
});