jQuery可不可以绑定onbeforeunload事件 试了下$(window).beforeunload(function(){...}),没反应~,现在还是用window.onbeforeunload = function(){...}来绑定函数,想问下jQuery可不可以实现onbeforeunload绑定呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 jquery只有unload没有onbeforeunload,你可以到jquery网站要查事件列表直接用window.onbeforeunload = function(){...}就可以了 没遇到过 ,可以去这里看看 。http://blog.csdn.net/hu_zhenghui/archive/2008/03/22/2206102.aspx jquery里好像只有unload没有onbeforeunload,如果说有的话,也应该是beforeunload而不是onbeforeunload,因为jquery里面的事件前面都是不带on的.JS里面有onbeforeunload.你试试beforeunload 可以吧:$("body").beforeunload(function(){}); $(function(){$("body").bind("beforeunload",function(){ })}) <!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> 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> unload事件将会在页面卸载时发生! jquery 如何刪除節點 光标全选单词 tabel的innerHtml赋值后无法在前台显示 求解:获得这个网站的链接直接的url js问题 做急呀!!!! 快来人救命头想爆了 jsp页面传递中文 insertAdjacentElement在FireFox里替代时出现的问题 如何可以使用户点击一次“登录”按钮后,不能再重复按该“登录”按钮 如何在js脚本里设置<td>的rowspan属性? emu和各位懂vml的幫個忙(等了六天才積累了60分,用光了) 如何使iframe自适应高度为100%,垂直滚动条在body部分? javascript思考题
直接用window.onbeforeunload = function(){...}就可以了
http://blog.csdn.net/hu_zhenghui/archive/2008/03/22/2206102.aspx
$("body").beforeunload(function(){});
$("body").bind("beforeunload",function()
{
})
})
<!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>
<!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>