2009-12-05 3 views
0

삭제 버튼으로 다음 MySQL을 가지고 있습니다.삭제할 경고 모달을 추가하는 방법

DELETE FROM mytable 
WHERE id = $id 

계속 진행하려면 jquery 모달을 추가하고 싶습니다. "예 | 아니오"

예를 클릭하면 삭제가 실행되고 아니오이면 모달을 종료하고 페이지로 돌아갑니다.

각 앵커의 ID가 동적으로 추가됩니다.

echo anchor('admin/categories/delete/'.$list['id'],'delete',array('class' => 'modalInput')); 

다음과 같은 html을 출력합니다.

HTML,이 작업을 수행하는 가장 좋은 방법은 무엇

... 
<tr valign='top'> 
<td>1</td> 
<td>Forsiden</td> 

<td align='center'>active</td> 
<td align='center'><a href="http://127.0.0.1/test/index.php/admin/categories/edit/1">edit</a> | <a href="http://127.0.0.1/test/index.php/admin/categories/delete/1">delete</a></td> 
</tr> 
<tr valign='top'> 
<td>2</td> 
<td>Front top</td> 
<td align='center'>active</td> 
<td align='center'><a href="http://127.0.0.1/test/index.php/admin/categories/edit/2">edit</a> | <a href="http://127.0.0.1/test/index.php/admin/categories/delete/2">delete</a></td> 

</tr> 
... 

?

답변

3
< script type="text/javascript"> 
<!-- 
function confirmation() { 
    var answer = confirm("Are you sure you want to delete?") 
    if (answer){ 
       $.post('/delete/post', {id: '345'}); 
    } 
} 
//--> 
< /script> 

이와 비슷한 것 같습니다. 당신은

1

하나의 옵션이 삭제 링크에게 클래스를 제공하는 것입니다 ... '345'인 데이터를 전달해야합니다, 그리고 당신은 같은 것을 할 수 있습니다 : 당신이 경우

// simple solution 
$('.delete_link').click(function() { 
    // if the user clicks "no", this will return false, stopping the link from being triggered 
    return confirm("Are you sure you want to delete?"); 
}); 

http://jqueryui.com/demos/dialog/#modal-confirmation

:

// ajax soluction 
$('.delete_link').click(function() { 
    if (confirm("Are you sure you want to delete?")) { 
     $.post(this.href); 
    } 
    return false; 
}); 

것은 또한 jqueryui의 확인 조동사를 확인하십시오 : 아약스로 일어날 삭제를 원하는

관련 문제