Jquery Datatable对话框 - 对话框仅打开第一个对话框
问题描述:
我目前正在使用DataTable和对话框。但是,似乎只能在第一次点击时打开对话窗口。每增加一次点击都会打开网站,但不会打开对话窗口。Jquery Datatable对话框 - 对话框仅打开第一个对话框
任何人都可以看到失败?代码如下
<script type="text/javascript" charset="UTF-8">
$(document).ready(function() {
function DialogInformation() {
var $link = $(this);
var $dialog = $('<div></div>').dialog({
autoOpen: false,
title: $link.attr('title'),
width: 800,
height: 400,
modal: true,
open: function()
{
$(this).load($link.attr('href'));
}
});
$dialog.dialog('open');
return false;
};
$('##named_datatable').dataTable({
"iDisplayLength": 10,
"bInfo" : false,
"bProcessing": false,
"bServerSide": false,
"sAjaxSource": 'getLists',
"sPaginationType": "full_numbers",
"aoColumns": [
{ "mDataProp": "Title" , "sTitle": "Titel"},
{ "mDataProp": "Info", "sTitle": "", "sClass": "info", "mRender": function (data, type, row) {
return '<a href="getLists/'+ data +'" title="Information -'+ row.Title + '" class="info">Info</a>'; }
},
{ "mDataProp": "Min" , "sTitle": "Min"},
{ "mDataProp": "Price" , "sTitle": "Preis"},
"fnDrawCallback": function() {
//bind the click handler script to the newly created elements held in the table
$('tbody td.info a.info').bind('click',DialogInformation);
}
});
});
答
.bind()重视在 'domready中' click事件。使用.on来附加事件处理程序,就像这样
$('tbody').on('click', 'td.info a.info',DialogInformation);
这可以在'ready()'本身完成,不需要使用'fnDrawCallback' – 2013-02-13 02:46:49