我在我的页面中使用了twitter boostrap数据表。在同一页面中,我为表中的每一行调用了删除选项。当我单击第1页中的删除按钮时,它打开确认对话框以删除记录,但是不在其他页面工作。请在此处查看我的健身代码。
我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Data table with all features</title>
<link href="css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<br>
<div style="width:900px; margin:0 auto; border:0px green dashed;" align="center">
<table class="table table-bordered" id="sample_1">
<thead>
<tr><th>Message</th> <th>Phone</th><th>Event Date</th><th>Message ID</th><th>Institution ID</th></tr>
</thead>
<tbody>
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
mysql_connect('localhost','root','');
mysql_select_db('sams');
$data = mysql_query("SELECT * FROM ( SELECT 1 AS type,institution_id,message,phone,event_date,message_id FROM custom_messages UNION ALL SELECT 2 AS type,institution_id,message,phone,event_date,message_id FROM send_messages) T1 where institution_id = '11' ORDER BY event_date");
$sno = 0;
while($record = mysql_fetch_assoc($data))
{
?>
<tr>
<td><?php echo $record['message']; ?></td>
<td><?php echo $record['phone']; ?></td>
<td><?php echo $record['event_date']; ?></td>
<td><?php echo $record['institution_id']; ?></td>
<td><a id=simpleConfirm_<?php echo $sno; ?>" custom-attr="destroy<?php echo $sno; ?>" href="#" class="delete">Delete</a></td>
</tr>
<?php
$sno++;
}
?>
</tbody>
</table>
</div>
<script src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/jquery.dataTables.js"></script>
<script type="text/javascript" src="js/DT_bootstrap.js"></script>
<script src="js/dynamic-table.js"></script>
<script>
$(function(){
$('.delete').on('click',function(){
var data = $(this).attr('custom-attr')
confirm(data)
})
})
</script>
</body>
</html>
请帮我解决问题。 感谢
答案 0 :(得分:1)
您可以在表格下方使用此代码,这意味着它适合我....
<script>
var $jc = jQuery.noConflict();
$jc('[id^="simpleConfirm_"]').each(function() {
$jc(this).confirm();
});
</script>
答案 1 :(得分:0)
你应该更新你的&#34; on&#34;声明
$("#sample_1").on('click','tr',function(){
var $temp = $(this);
var $target = $temp.find("td:eq(4)").find("a");
if(!!$target){
var data = $target.attr('custom-attr');
confirm(data);
}});
你可以在下面看到jsbin url:
相关