$.fn.enable_changed_form_confirm = function () {
var _f = this;
$(':text, :password, textarea', this).each(function() {
$(this).attr('_value', $(this).val());
});
$(':checkbox, :radio', this).each(function() {
var _v = this.checked ? 'on' : 'off';
$(this).attr('_value', _v);
});
$('select', this).each(function() {
$(this).attr('_value', this.options[this.selectedIndex].value);
});
$(this).submit(function() {
window.onbeforeunload = null;
});
window.onbeforeunload = function() {
if(is_form_changed(_f)) {
return "You will lose any unsaved content.";
}
}
}
function is_form_changed(f) {
var changed = false;
$(':text, :password, textarea', f).each(function() {
var _v = $(this).attr('_value');
if(typeof(_v) == 'undefined') _v = '';
if(_v != $(this).val()) changed = true;
});
$(':checkbox, :radio', f).each(function() {
var _v = this.checked ? 'on' : 'off';
if(_v != $(this).attr('_value')) changed = true;
});
$('select', f).each(function() {
var _v = $(this).attr('_value');
if(typeof(_v) == 'undefined') _v = '';
if(_v != this.options[this.selectedIndex].value) changed = true;
});
return changed;
}
$(function() {
$('form').enable_changed_form_confirm();
});
分享到:
相关推荐
jquery截图保存 C#源代码+jquery实例.
jQuery带页面跳转的确认提示框代码 jQuery带页面跳转的确认提示框代码
jquery 监听页面按钮 jquery1.5 监听事件
jQuery ui页面全屏滚动fullPage.js插件页面滚动 jQuery ui页面全屏滚动fullPage.js插件页面滚动
jQuery调整页面字号大小,jQuery调整页面字号大小,jQuery调整页面字号大小
jQuery实例-信息提示jQuery实现 jQuery实例-信息提示jQuery实现
自己写的一段jquery小代码,实现了jquery的页面传值功能,代码已经编译运行通过,请各位大侠指教!
用jquerymobile开发时,两个页面间跳转往往需要传递参数,此文档是代码示例
可以拖拽的布局页面,jQuery.UI插件
jquery web页面 apijquery web页面 apijquery web页面 apijquery web页面 apijquery web页面 apijquery web页面 api
jQuery仿京东页面制作,组件封装。适用于初学jQuery的项目。逻辑思路清晰。代码简洁
jquery刷新页面和JS常用的函数。另外jQuery实现跨域调用的问题可以联系我。
支持input type为 text,textarea,checkbox,radio,select,password,hidden的草稿自动保存 hidden的特殊性,因为hidden要手动触发change事件,当值改变的时候要 手动代码 .change() 触发一下才会保存相应的草稿 要实现...
完美的jquery页面布局c完美的jquery页面布局c完美的jquery页面布局c完美的jquery页面布局
jquery-Jcrop实现图片裁剪截图上传和保存。
php jquery mysql拖动层并保存数据库
jquery实现的等待加载页面 即实现更好的用户交互效果
jquery.joyride页面功能分步指引插件一步步提示页面 jquery.joyride页面功能分步指引插件一步步提示页面
jquery-autocomplete 智能提示jquery-autocomplete 智能提示jquery-autocomplete 智能提示jquery-autocomplete 智能提示
JQUERY实现iframe页面切换功能,轻松简单、灵活方便快速,代码实例,测试通过