js 实现简单弹出'确认'、'取消' 提示

2019-11-20  本文已影响0人  茉茉杨

一种:

<a href="javascript:if(confirm('确实要删除该内容吗?')){location='http://www.google.com'}">弹出窗口</a>

讲解:分解成三部分来看:

<a href="javascript: // ">表示点击超链接后执行相应的javascript代码。

confirm() 表示一个要求确认的对话框,用户点击确定返回true,取消则返回false。

if(confirm())则表示,如果用户选择了确定,则执行if代码,否则什么也不做。

二种:

<button onclick="logout()">退出</button>

function logout(){

    if(window.confirm('你确定要取消交易吗?')){

          //alert("确定");

           return true;

     }else{

            //alert("取消");

            return false;

     }

  }

上一篇下一篇

猜你喜欢

热点阅读