JQuery实现离开页面时检测修改并提示保存
window.onbeforeunload = function()
{
if(is_form_changed())
{
return "您的修改内容还没有保存,您确定离开吗?";
}
}
function is_form_changed()
{
//检测页面是否有保存按钮
var t_save = jQuery("#t_save");
//检测到保存按钮,继续检测元素是否修改
if(t_save.length>0)
{
var is_changed = false;
jQuery("#A4 input, #A4 textarea, #A4 select").each(function()
{
var _v = jQuery(this).attr('_value');
if(typeof(_v) == 'undefined')
_v = '';
if(_v != jQuery(this).val())
is_changed = true;
});
return is_changed;
}
return false;
}
jQuery(document).ready(function()
{
jQuery("#A4 input, #A4 textarea, #A4 select").each(function()
{
jQuery(this).attr('_value', jQuery(this).val());
});
});
浙公网安备 33010602011771号