Laravel注销按钮收到警告消息

时间:2018-04-03 08:08:59

标签: javascript php jquery html laravel

我想在网站的任何位置实施该功能,当用户点击Logout按钮时,获得javascript confirm box

Laravel注销按钮看起来像:

       <a class="dropdown-item" href="{{route('logout')}}" onclick="event.preventDefault();document.getElementById('logout-form').submit();">
            <span class="text-danger">
                <i class="fa fa-fw fa-sign-out"></i>Logout
            </span>
         </a> 

1 个答案:

答案 0 :(得分:0)

您可以使用javascript confirm()功能。

<a class="dropdown-item" href="{{route('logout')}}" onclick="return logout(event);">
     <span class="text-danger">
        <i class="fa fa-fw fa-sign-out"></i>Logout
     </span>
</a> 

<script type="text/javascript">
    function logout(event){
            event.preventDefault();
            var check = confirm("Do you really want to logout?");
            if(check){ 
               document.getElementById('logout-form').submit();
            }
     }
</script>

     <a class="dropdown-item" href="{{route('logout')}}" onclick="event.preventDefault();var check = confirm("Do you really want to logout?");if(check){document.getElementById('logout-form').submit();}">
        <span class="text-danger">
            <i class="fa fa-fw fa-sign-out"></i>Logout
        </span>
     </a>