开发者社区 问答 正文

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 2670 分享 版权
1 条回答
写回答
取消 提交回答
问答地址: