我目前正在使用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);
}
} );
} );
答案 0 :(得分:1)
.bind()在'domready'处附加click事件。使用像这样的.on附加事件处理程序
$('tbody').on('click', 'td.info a.info',DialogInformation);