我想要得到一个确认消息点击删除(这可能是一个按钮或图像)。如果用户选择“Ok”,那么删除就完成了,否则如果点击“Cancel”,什么都不会发生。
当点击按钮时,我尝试回显这个,但是回显的东西使我的输入框和文本框失去了它们的样式和设计。
我想要得到一个确认消息点击删除(这可能是一个按钮或图像)。如果用户选择“Ok”,那么删除就完成了,否则如果点击“Cancel”,什么都不会发生。
当点击按钮时,我尝试回显这个,但是回显的东西使我的输入框和文本框失去了它们的样式和设计。
当前回答
如果你对一些快速漂亮的解决方案与css格式感兴趣,你可以使用SweetAlert
$(function(){ $(".delete").click(function(){ 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 }).then(isConfirmed => { if(isConfirmed) { $(".file").addClass("isDeleted"); swal("Deleted!", "Your imaginary file has been deleted.", "success"); } }); }); }); html { zoom: 0.7 } /* little "hack" to make example visible in stackoverflow snippet preview */ body > p { font-size: 32px } .delete { cursor: pointer; color: #00A } .isDeleted { text-decoration:line-through } <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script> <link rel="stylesheet" href="http://t4t5.github.io/sweetalert/dist/sweetalert.css"> <p class="file">File 1 <span class="delete">(delete)</span></p>
其他回答
var x = confirm("Are you sure you want to send sms?");
if (x)
return true;
else
return false;
对于“删除确认消息”使用:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Searching.aspx/Delete_Student_Data",
data: "{'StudentID': '" + studentID + "'}",
dataType: "json",
success: function (data) {
alert("Delete StudentID Successfully");
return true;
}
非常简单
function archiveRemove(any) {
var click = $(any);
var id = click.attr("id");
swal.fire({
title: 'Are you sure !',
text: "?????",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'yes!',
cancelButtonText: 'no'
}).then(function (success) {
if (success) {
$('a[id="' + id + '"]').parents(".archiveItem").submit();
}
})
}
在按钮的onclick事件中写入以下内容:
var result = confirm("Want to delete?");
if (result) {
//Logic to delete the item
}
HTML
<input onclick="return myConfirm();" type="submit" name="deleteYear" class="btn btn-danger" value="Delete">
Javascript
<script>
function myConfirm() {
var result = confirm("Want to delete?");
if (result==true) {
return true;
} else {
return false;
}
}