Skip to content

Instantly share code, notes, and snippets.

@comeontom
comeontom / gist:f80681282d6802b384a7dc3822c4c387
Created July 5, 2016 02:44
页面切换时,弹出提示
// 离开页面弹出提示代码: 绑定beforeunload事件
addBeforeunload: function() {
this.delBeforeunload();
$(window).bind('beforeunload',function(e){
var confirmationMessage = '确定离开此页吗?本页不需要刷新或后退';
(e || window.event).returnValue = confirmationMessage;
return confirmationMessage;
});
},
//离开页面弹出提示代码: 解除绑定
@comeontom
comeontom / jquery
Created July 5, 2017 00:52
浏览器上复制
function select(element) {
var selectedText;
var isReadOnly = element.hasAttribute('readonly');
if (!isReadOnly) {
element.setAttribute('readonly', '');
}
element.select();
element.setSelectionRange(0, element.value.length);
if (!isReadOnly) {
element.removeAttribute('readonly');