삭제하기 전에 확인 메시지를 표시하는 방법은 무엇입니까?
삭제 (버튼 또는 이미지)를 클릭하면
확인 메시지
를 받고 싶습니다 . 사용자가 '
Ok
'를 선택하면 삭제가 수행되고 그렇지 않으면 '
Cancel
'를 클릭하면 아무 일도 일어나지 않습니다.버튼을 클릭 할 때 에코를 시도했지만 에코로 인해 입력 상자와 텍스트 상자의 스타일과 디자인이 손실됩니다.
onclick
버튼 이있는 경우 이것을 작성하십시오 .
var result = confirm("Want to delete?");
if (result) {
//Logic to delete the item
}
다음과 같이 더 잘 사용할 수 있습니다
<a href="url_to_delete" onclick="return confirm('Are you sure you want to delete this item?');">Delete</a>
이것은 눈에 거슬리지 않는 JavaScript와 확인 메시지가 HTML로 유지되는 방식입니다.
<a href="/delete" class="delete" data-confirm="Are you sure to delete this item?">Delete</a>
이것은 IE 9 이상과 호환되는 순수한 바닐라 JS입니다.
var deleteLinks = document.querySelectorAll('.delete');
for (var i = 0; i < deleteLinks.length; i++) {
deleteLinks[i].addEventListener('click', function(event) {
event.preventDefault();
var choice = confirm(this.getAttribute('data-confirm'));
if (choice) {
window.location.href = this.getAttribute('href');
}
});
}
실제로 참조하십시오 :
http://codepen.io/anon/pen/NqdKZq
function ConfirmDelete()
{
var x = confirm("Are you sure you want to delete?");
if (x)
return true;
else
return false;
}
<input type="button" onclick="ConfirmDelete()">
이 시도. 그것은 나를 위해 작동
<a href="delete_methode_link" onclick="return confirm('Are you sure you want to Remove?');">Remove</a>
user1697128 개선 (아직 댓글을 달 수 없기 때문에)
<script>
function ConfirmDelete()
{
var x = confirm("Are you sure you want to delete?");
if (x)
return true;
else
return false;
}
</script>
<button Onclick="return ConfirmDelete();" type="submit" name="actiondelete" value="1"><img src="images/action_delete.png" alt="Delete"></button>
취소를 누르면 양식 제출이 취소됩니다.
나는 이것을하는 방법을 제공하고 싶다 :
<form action="/route" method="POST">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="the_token">
<button type="submit" class="btn btn-link" onclick="if (!confirm('Are you sure?')) { return false }"><span>Delete</span></button>
</form>
매우 간단하고 한 줄의 코드입니다.
<a herf="#" title="delete" class="delete" onclick="return confirm('Are you sure you want to delete this item')">Delete</a>
HTML :
<a href="#" class="delete" data-confirm="Are you sure to delete this item?">Delete</a>
jQuery 사용하기 :
$('.delete').on("click", function (e) {
e.preventDefault();
var choice = confirm($(this).attr('data-confirm'));
if (choice) {
window.location.href = $(this).attr('href');
}
});
<form onsubmit="return confirm('Are you sure?');" />
양식에 적합합니다. 양식 관련 질문 :
JavaScript 양식 제출-제출 확인 또는 취소 대화 상자
연습
<form name=myform>
<input type=button value="Try it now"
onClick="if(confirm('Format the hard disk?'))
alert('You are very brave!');
else alert('A wise decision!')">
</form>
웹 원본 :
http://www.javascripter.net/faq/confirm.htm
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
},
function(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="http://t4t5.github.io/sweetalert/dist/sweetalert-dev.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>
<a href="javascript:;" onClick="if(confirm('Are you sure you want to delete this product')){del_product(id);}else{ }" class="btn btn-xs btn-danger btn-delete" title="Del Product">Delete Product</a>
<!-- language: lang-js -->
<script>
function del_product(id){
$('.process').css('display','block');
$('.process').html('<img src="./images/loading.gif">');
$.ajax({
'url':'./process.php?action=del_product&id='+id,
'type':"post",
success: function(result){
info=JSON.parse(result);
if(result.status==1){
setTimeout(function(){
$('.process').hide();
$('.tr_'+id).hide();
},3000);
setTimeout(function(){
$('.process').html(result.notice);
},1000);
} else if(result.status==0){
setTimeout(function(){
$('.process').hide();
},3000);
setTimeout(function(){
$('.process').html(result.notice);
},1000);
}
}
});
}
</script>
HTML
<input onclick="return myConfirm();" type="submit" name="deleteYear" class="btn btn-danger" value="Delete">
자바 스크립트
<script>
function myConfirm() {
var result = confirm("Want to delete?");
if (result==true) {
return true;
} else {
return false;
}
}
PHP & MySQL에서 무언가를 삭제할 때 형태 메시지를 설정하려면 ...이 스크립트 코드를 사용하십시오 :
<script>
function Conform_Delete()
{
return conform("Are You Sure Want to Delete?");
}
</script>
이 HTML 코드를 사용하십시오 :
<a onclick="return Conform_Delete()" href="#">delete</a>
function del_confirm(msg,url)
{
if(confirm(msg))
{
window.location.href=url
}
else
{
false;
}
}
<a onclick="del_confirm('Are you Sure want to delete this record?','<filename>.php?action=delete&id=<?<id> >')"href="#"></a>
jQuery 사용하기 :
$(".delete-link").on("click", null, function(){
return confirm("Are you sure?");
});
나는 이것이 오래
되었다는
것을 알고 있지만 나는 대답이 필요하지만 이것들 중 하나는 아니지만 alpesh 의 대답은 나를 위해 일했고 같은 문제가있는 사람들과 공유하고 싶었습니다.
<script>
function confirmDelete(url) {
if (confirm("Are you sure you want to delete this?")) {
window.open(url);
} else {
false;
}
}
</script>
일반 버전 :
<input type="button" name="delete" value="Delete" onClick="confirmDelete('delete.php?id=123&title=Hello')">
내 PHP 버전 :
$deleteUrl = "delete.php?id=" .$id. "&title=" .$title;
echo "<input type=\"button\" name=\"delete\" value=\"Delete\" onClick=\"confirmDelete('" .$deleteUrl. "')\"/>";
이것은 공개적으로 올바른 방법이 아닐 수도 있지만 개인 사이트에서 나에게 도움이되었습니다. :)
var txt;
var r = confirm("Press a button!");
if (r == true) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
}
var txt;
var r = confirm("Press a button!");
if (r == true) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
}
<SCRIPT LANGUAGE="javascript">
function Del()
{
var r=confirm("Are you sure?")
if(r==true){return href;}else{return false;}
}
</SCRIPT>
그것에 대한 귀하의 링크 :
<a href='edit_post.php?id=$myrow[id]'> Delete</a>
onclick 핸들러는 함수 호출 후 false를 리턴해야합니다. 예를 들어.
onclick="ConfirmDelete(); return false;">
가장 간단한 눈에 띄지 않는 해결책은 다음과 같습니다.링크:
<a href="http://link_to_go_to_on_success" class="delete">Delete</a>
자바 스크립트 :
$('.delete').click(function () {
return confirm("Are you sure?");
});
<a href="javascript:;" onClick="if(confirm('Are you sure you want to delete this product')){del_product(id);}else{ }" class="btn btn-xs btn-danger btn-delete" title="Del Product">Delete Product</a>
function del_product(id){
$('.process').css('display','block');
$('.process').html('<img src="./images/loading.gif">');
$.ajax({
'url':'./process.php?action=del_product&id='+id,
'type':"post",
success: function(result){
info=JSON.parse(result);
if(result.status==1){
setTimeout(function(){
$('.process').hide();
$('.tr_'+id).hide();
},3000);
setTimeout(function(){
$('.process').html(result.notice);
},1000);
}else if(result.status==0){
setTimeout(function(){
$('.process').hide();
},3000);
setTimeout(function(){
$('.process').html(result.notice);
},1000);
}
}
});
}
다음은 className과 바인딩 이벤트를 사용하는 순수 JS의 또 다른 간단한 예입니다.
var eraseable = document.getElementsByClassName("eraseable");
for (var i = 0; i < eraseable.length; i++) {
eraseable[i].addEventListener('click', delFunction, false); //bind delFunction on click to eraseables
}
function delFunction(){
var msg = confirm("Are you sure?");
if (msg == true) {
this.remove(); //remove the clicked element if confirmed
}
};
<button class="eraseable">
<img class="eraseable" src="http://zelcs.com/wp-content/uploads/2013/02/stackoverflow-logo-dumpster.jpg" style="width:100px;height:auto;">
Delete me</button>
<button class="eraseable">
<img class="eraseable" src="http://zelcs.com/wp-content/uploads/2013/02/stackoverflow-logo-dumpster.jpg" style="width:100px;height:auto;">
Delete me</button>
<button class="eraseable">
<img class="eraseable" src="http://zelcs.com/wp-content/uploads/2013/02/stackoverflow-logo-dumpster.jpg" style="width:100px;height:auto;">
Delete me</button>
<script>
function deleteItem()
{
var resp = confirm("Do you want to delete this item???");
if (resp == true) {
//do something
}
else {
//do something
}
}
</script>
사용 하여이 함수를 호출
onClick
"삭제 확인 메시지"의 경우 다음을 사용하십시오.
$.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;
}
자바 스크립트 삭제 예제가있는 Angularjs html 코드
<button ng-click="ConfirmDelete(single_play.play_id)" type="submit" name="actiondelete" value="1"><img src="images/remove.png" alt="Delete"></button>
"single_play.play_id"는 삭제 작업 중에 매개 변수를 전달하려는 모든 각도 변수입니다. 앱 모듈 내부의 Angularjs 코드
$scope.ConfirmDelete = function(yy)
{
var x = confirm("Are you sure you want to delete?");
if (x) {
// Action for press ok
$http({
method : 'POST',
url : 'sample.php',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: $.param({ delete_play_id : yy})
}).then(function (response) {
$scope.message = response.data;
});
}
else {
//Action for cancel
return false;
}
}
옵션 상자를 선택하는 것이 훨씬 어렵습니다. 해결책은 다음과 같습니다.
<select onchange="if (this.value == 'delete' && !confirm('THIS ACTION WILL DELETE IT!\n\nAre you sure?')){this.value=''}">
<option value=''> </option>
<option value="delete">Delete Everything</option>
</select>
function confirmDelete()
{
var r=confirm("Are you sure you want to delte this image");
if (r==true)
{
//User Pressed okay. Delete
}
else
{
//user pressed cancel. Do nothing
}
}
<img src="deleteicon.png" onclick="confirmDelete()">
confirmDelete로 일부 데이터를 전달하여 삭제할 항목을 결정할 수 있습니다.
var x = confirm("Are you sure you want to send sms?");
if (x)
return true;
else
return false;
참고URL : https://stackoverflow.com/questions/9139075/how-to-show-a-confirm-message-before-delete
'programing' 카테고리의 다른 글
.NET에서 파일 규칙 당 하나의 클래스? (0) | 2020.05.18 |
---|---|
Java에서 sha256으로 문자열을 해시하는 방법은 무엇입니까? (0) | 2020.05.18 |
삼항 또는 삼항? (0) | 2020.05.18 |
모든 파일에 대해 Nginx 403 금지 (0) | 2020.05.18 |
상점을 여는 데 사용 된 모델이 상점을 만드는 데 사용 된 모델과 호환되지 않습니다 (0) | 2020.05.18 |