javascript
  • php
  • html
  • mysql
  • 2016-07-23 67 views 0 likes 
    0

    有人可以幫我解決我的問題。每當我想從我的表中刪除數據會彈出一個對話框,如果我要刪除的項目,但eventhough我按下取消按鈕還是它刪除的項目。這裏是我的代碼確認對話框效果不佳

    echo"<td> <center><a href ='delete.php?house_id=$id'><button type='button' onclick='ConfirmDelete()'' class='btn btn-info btn-md'><span class='glyphicon glyphicon-trash'></span>Delete</button></a></center></td>"; 
    echo"</tr>"; 
    $count++; 
    } 
    ?> 
    <script type="text/javascript"> 
    function ConfirmDelete(){ 
        if (confirm("Delete Account?")) 
         location.href='delete.php'; 
        } 
    </script> 
    
    +1

    您的功能不會關閉。在'' –

    回答

    1

    試試這個:

    <script type="text/javascript"> 
    function ConfirmDelete(){ 
        if (confirm("Delete Account?")){ 
         location.href='delete.php'; 
        } 
        else { 
         return false; 
        } 
        } 
    </script> 
    

    而且更新onclick='return ConfirmDelete()'

    +0

    之前需要另外一個'}'它仍然會刪除該項目 –

    +0

    謝謝...它的工作原理...謝謝 –

    0

    閉上你的功能

    <script type="text/javascript"> 
    function ConfirmDelete(){ 
        if (confirm("Delete Account?")) 
         location.href='delete.php'; 
        } 
    } 
    </script> 
    
    0

    您的代碼中有語法錯誤。更換此零件:

    function ConfirmDelete(){ 
        if (confirm("Delete Account?")){ 
         location.href='delete.php'; 
        } 
    } 
    
    相關問題