开发者社区> 问答> 正文

beforeunload 事件可以绑定到什么元素上面?

var attention = function (e) {
  var confirmationMessage = "修改尚未保存!";
  console.log(e.);
  (e || window.event).returnValue = confirmationMessage; // Gecko and Trident
  return confirmationMessage; // Gecko and WebKit
};

window.addEventListener('beforeunload', attention);

绑定到 window 上时起效,绑定到其他页面元素则不行,例如

var input = document.querySelector('table>input')
input.addEventListener('beforeunload', attention)

展开
收起
杨冬芳 2016-06-20 17:41:25 2525 0
1 条回答
写回答
取消 提交回答
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载