asp.net mvc和js - 跟踪关闭时是否有任何更改

时间:2014-03-11 16:48:40

标签: javascript asp.net-mvc validation

当用户离开(或刷新)页面时,我试图显示确认消息。 但是只有在未保存的更改时才需要这个

我使用window.onbeforeunload。

但无法跟踪jquery change()或live()方法。 我有最新的Chrome和jquery 1.8.xx

至于控制,我只有输入。

具有强烈身份的人{idTruckTrailerTag'。

使用asp.net mvc自动生成休息 喜欢" Tasks_0__ActualDate"," Tasks_0__ActualTime"。 内部数字增长,可以有2位甚至3位数。

有人能用真正有效的榜样帮助我吗?

function confirmExit()
{
    return "All changes made will be lost.";
}

$(document).submit(function(){
    window.onbeforeunload = null;
});

$(document).ready(function() {

    // page loaded fine
    var textbox = document.getElementById("idTruckTrailerTag");
    if (textbox != null)
        window.onbeforeunload = confirmExit;

    etc...


@Html.TextBoxFor(m => m.TruckTrailerTag, new { @id = "idTruckTrailerTag", @style = "height: 20px; min-height: 20px; border:1px solid #aaaaaa; color: #414040;" })

@{var loadActualDateValue = Model.Tasks[i].ActualDate.HasValue ? Model.Tasks[i].ActualDate.Value.ToString("yyyy-MM-dd") : string.Empty;}
        @Html.TextBoxFor(model => model.Tasks[i].ActualDate, new { @class = "actual-date", @Value = loadActualDateValue, @style = "height: 20px; min-height: 20px; border:1px solid #aaaaaa; color: #414040;" })

@Html.TextBoxFor(model => model.Tasks[i].ActualTime, new { @textInputType = "Time", @style = "width: 125px; height: 20px; min-height: 20px; border:1px solid #aaaaaa; color: #414040;" })

0 个答案:

没有答案