admin管理员组文章数量:1332377
I'm trying to use sweet alert as a dialog to confirm the deletion of an entry on a table. There's a column on each table row which has a button which opens a 'Sweet Alert' confirm dialog.
The code of my table is as follow:
<tr>
<!-- Other Table Colums -->
<td>
<button userid="<?php echo $row['id']; ?>" id="<?php echo('bn_delete_' . $row['id']); ?>" class="btn btn-danger btn-xs warning-message-parameter">Delete</button>
<td>
</tr>
The code for my sweet alert dialog is:
swal({ title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false },
function(){
swal("Deleted!", "Your imaginary file has been deleted.", "success"); });
When the user clicks yes on the dialog, I want to get the id of the button which the user just clicked. That way I'll be able to get the value of the attribute userid which I can then use to delete the entry from database.
I'm trying to use sweet alert as a dialog to confirm the deletion of an entry on a table. There's a column on each table row which has a button which opens a 'Sweet Alert' confirm dialog.
The code of my table is as follow:
<tr>
<!-- Other Table Colums -->
<td>
<button userid="<?php echo $row['id']; ?>" id="<?php echo('bn_delete_' . $row['id']); ?>" class="btn btn-danger btn-xs warning-message-parameter">Delete</button>
<td>
</tr>
The code for my sweet alert dialog is:
swal({ title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false },
function(){
swal("Deleted!", "Your imaginary file has been deleted.", "success"); });
When the user clicks yes on the dialog, I want to get the id of the button which the user just clicked. That way I'll be able to get the value of the attribute userid which I can then use to delete the entry from database.
Share Improve this question asked Feb 21, 2016 at 11:55 Melvin M.Melvin M. 3,5003 gold badges16 silver badges23 bronze badges1 Answer
Reset to default 5You can get the id of the clicked button by retrieving it when the button is clicked, and passing it as a parameter to the plugin callback.
Take a look at the following implementation:
$('#openSwal').on('click', function(e) {
var id = $(e.currentTarget).attr("id");
var userId = $(e.currentTarget).data("user-id");
var region = "myregion";
swal({
html: true,
title: '' + region,
showCancelButton: true,
showConfirmButton: true,
confirmButtonText: "save",
text: "<span onclick='save()'>l</span>"
}, function() {
save(id, userId);
});
});
function save(id, userId) {
console.log(id);
console.log(userId);
}
http://jsfiddle/jwsho9L9/4/
本文标签: javascriptGetting element Id Sweet AlertStack Overflow
版权声明:本文标题:javascript - Getting element Id Sweet Alert - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742306272a2449979.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论