我有一个表,其中包含删除特定用户的删除按钮。因此,当我单击删除按钮时,会显示确认模式,当我单击删除按钮时,必须删除特定用户。
触发模态的按钮
<td style="white-space: nowrap; width: 1%;">
<div class="tabledit-toolbar btn-toolbar" style="text-align: left;">
<div class="btn-group btn-group-sm" style="float: none;">
<button onclick="location.href='<?php echo base_url('Employee/viewEmployee/'.$id) ?> ' " type="button" class="tabledit-delete-button btn btn-inverse waves-effect waves-light" style="float: none;margin: 5px;">
<span class="fa fa-eye"></span>
</button>
<button onclick="location.href='<?php echo base_url('Employee/editEmployeeView/'.$id) ?> ' " type="button" class="tabledit-edit-button btn btn-primary waves-effect waves-light" style="float: none;margin: 5px;">
<span class="icofont icofont-ui-edit"></span>
</button>
<button type="button" id="<?php echo $id; ?>" class="tabledit-delete-button btn btn-danger waves-effect waves-light" data-toggle="modal" data-target="#default-Modal" data-id="<?php echo $id; ?>" data-yourparameter="<?php echo $id; ?>" style="float: none;margin: 5px;">
<span class="icofont icofont-ui-delete"></span>
</button>
</div>
</div>
</td>
资本
<div class="modal fade" id="default-Modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Delete Employee</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h5>Are you sure?</h5><br>
<p>By proceeding ,the data will be permanently deleted.You will not be able to recover once it is deleted</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default waves-effect " data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger waves-effect waves-light " onclick="location.href='<?php echo base_url('Employee/deleteEmployee/'.$id) ?>' ">Delete</button>
</div>
</div>
</div>
目前,当我单击按钮时,模式默认打开。除了jquery库之外,我没有编写任何其他脚本。
我想要做的是将id传递给模态。
我是javascript和jquery的新手。我尝试了其他问题中提到的一些答案,但不管我使用的代码如何,它都没有用;模式是由jquery库的方法打开的(我认为)。
非常感谢任何帮助。谢谢。
我认为您发布ID以使用PHP
处理它。
使用onclick
函数替换onclick方法中的值:
把它放在代码的底部!
<script>
$(".tabledit-delete-button").each(function(index) {
$(this).on("click", function(){
var myID = $(this).data('id');
$("#default-Modal .btn-danger").attr("onclick","location.href='/Employee/deleteEmployee/'" + myID);
});
});
</script>
然后你在模态中有你的价值。 这可以防止需要多个相同的模态。
看看我为你制作的这个JSfiddle:https://jsfiddle.net/Jbotman/f4voxes8/1/