试了下$(window).beforeunload(function(){...}),没反应~,现在还是用window.onbeforeunload = function(){...}来绑定函数,想问下jQuery可不可以实现onbeforeunload绑定呢?

解决方案 »

  1.   

    jquery只有unload没有onbeforeunload,你可以到jquery网站要查事件列表
    直接用window.onbeforeunload = function(){...}就可以了
      

  2.   

    没遇到过 ,可以去这里看看 。
    http://blog.csdn.net/hu_zhenghui/archive/2008/03/22/2206102.aspx
      

  3.   

    jquery里好像只有unload没有onbeforeunload,如果说有的话,也应该是beforeunload而不是onbeforeunload,因为jquery里面的事件前面都是不带on的.JS里面有onbeforeunload.你试试beforeunload
      

  4.   

    可以吧:
    $("body").beforeunload(function(){});
      

  5.   

    $(function(){
    $("body").bind("beforeunload",function()
    {
     
    })
    })
      

  6.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>beforeunload</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type='text/javascript'> 
    /* <![CDATA[ */
    $(document).ready(function(){
    $(window).bind("beforeunload",function(){
    alert("test");
    });
    });
    /* ]]> */
    </script>
    </head><body>
    <div>尝试刷新这个页面</div>
    </body>
    </html>
      

  7.   

    jquery封装的函数:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>unload</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type='text/javascript'> 
    /* <![CDATA[ */
    $(document).ready(function(){
    $(window).unload( function () { alert("Bye now!"); } );
    });
    /* ]]> */
    </script>
    </head><body>
    <div>尝试刷新这个页面</div>
    </body>
    </html>
      

  8.   

    unload事件将会在页面卸载时发生!