我有一個jQuery事件綁定到數據表中的一個元素,當表是全寬度時,它沒有問題觸發。但是,當表被摺疊並且應用數據表響應時,事件不會觸發。控制檯中沒有任何關於任何錯誤的信息。響應式數據表上的jQuery事件不起作用
你可以看到下面的代碼,並嘗試一下在這裏的jsfiddle:
點擊垃圾桶,你會得到一個彈出。調整頁面大小直到表格摺疊。打開列以顯示垃圾桶,當你點擊它時什麼都不會發生。
任何想法?
<!DOCTYPE html>
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.7/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/tabletools/2.2.3/css/dataTables.tableTools.min.css">
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/responsive/1.0.6/css/dataTables.responsive.css">
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script type="text/javascript" src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="//cdn.datatables.net/tabletools/2.2.3/js/dataTables.tableTools.min.js"></script>
<script type="text/javascript" src="//cdn.datatables.net/responsive/1.0.6/js/dataTables.responsive.min.js"></script>
<script>
$(document).ready(function() {
// load data tables if element found
if (document.getElementById('data-table')) {
$('#data-table').DataTable({
"responsive": true,
"paging": true,
"searching": true,
"ordering": false,
"info": false
});
}
$(".deleteMe").bind('click', function() {
var dataString = $(this).attr('data');
alert(dataString);
});
});
</script>
</head>
<body>
<table width="100%" id="data-table" class="display dataTable">
<thead>
<tr>
<th>Col</th>
<th>Col</th>
<th>Col</th>
<th>Col</th>
<th>Col</th>
<th width="10%">Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>asfas</td>
<td align="middle">fgfg</td>
<td align="middle">COMPLETED</td>
<td align="middle">4</td>
<td align="middle">4</td>
<td width="10%">
<a href="#">
<i alt="Delete" class="fa fa-trash fa-lg deleteMe" id="questionDelete" data="some text 1"></i>
</a>
</td>
</tr>
<tr>
<td>sdfs</td>
<td align="middle">test</td>
<td align="middle">2014-02-28</td>
<td align="middle">1</td>
<td align="middle">0</td>
<td width="10%">
<a href="#">
<i alt="Delete" class="fa fa-trash fa-lg deleteMe" id="questionDelete" data="some text 2"></i>
</a>
</td>
</tr>
<tr>
<td>sfdsf</td>
<td align="middle">fgfg</td>
<td align="middle">COMPLETED</td>
<td align="middle">4</td>
<td align="middle">4</td>
<td width="10%">
<a href="#">
<i alt="Delete" class="fa fa-trash fa-lg deleteMe" id="questionDelete" data="some text 3"></i>
</a>
</td>
</tr>
</tbody>
</table>
</body>
</html>
僅供參考,這是無效的HTML標記,ID必須在文檔方面獨特 –