jq点击关闭按钮,关闭当前页面

这样写有什么问题吗? 为什么关闭不了,也不报错 谢谢


    <div class="close">

                <a href="#">关闭</a>

            </div>

<script type="text/javascript">

    $('.close').on('click', function() {

        if(confirm("您确定要关闭本页吗?")) {

            window.opener = null;

            window.open('', '_self');

            window.close();

        } else {}

    

    })


POPMUISE
浏览 10216回答 1
1回答

30秒到达战场

<!DOCTYPE html><html><head>&nbsp; &nbsp; <meta charset="UTF-8">&nbsp; &nbsp; <title></title>&nbsp; &nbsp; <script src="js/jquery-1.9.1.min.js"></script>&nbsp; &nbsp; <style>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; </style></head><body>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <div id="div">&nbsp; &nbsp; &nbsp; &nbsp; <a href="javascript:;">关闭页面</a>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; </div>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <script type="text/javascript">&nbsp; &nbsp; &nbsp; &nbsp; $('#div').on('click',function(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(confirm('你确定关闭页面吗')){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closewin();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; function closewin(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.opener=null;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.close();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; </script></body></html>没毛病、就是这样
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript