在取消提示上刷新页面

时间:2011-11-23 19:17:57

标签: javascript asp.net

问题:

我有一个网页。当我填写数据并点击保存时,它会给我一个确认弹出框。取消时我想刷新页面。因此输入的数据将被清除。

以下是目前确认的代码:

function checknumber() {
    var x = document.getElementById('<%=view_txt_pixelwidth.ClientID%>').value;
    var y = document.getElementById('<%=view_txt_pixelheight.ClientID%>').value;
    var z = document.getElementById('<%=view_txt_printleft.ClientID%>').value;
    var a = document.getElementById('<%=view_txt_printtop.ClientID%>').value;
    var b = document.getElementById('<%=view_txt_printwidth.ClientID%>').value;
    var c = document.getElementById('<%=view_txt_printheight.ClientID%>').value;                       

    var anum = /(^\d+$)|(^\d+\.\d+$)/
    if ((anum.test(x)) && (anum.test(y)) && (anum.test(z)) && (anum.test(a)) && (anum.test(b)) && (anum.test(c)))
        testresult = confirm('save change?');
    else {
        alert("Please input a valid number!")
        testresult = false
    }
    return (testresult);
}                        
function Validate_view() {
    var value = document.getElementById('<%=view_txt_name.ClientID%>').value;
    var value2 = document.getElementById('<%=view_txt_title.ClientID%>').value;
    var value3 = document.getElementById('<%=view_txt_description.ClientID%>').value;
    var value4 = document.getElementById('<%=view_txt_pixelwidth.ClientID%>').value;
    var value5 = document.getElementById('<%=view_txt_pixelheight.ClientID%>').value;
    if (value == '' || value2 == '' || value3 == '' || value4 == '' || value5 == '') {
        ValidatorEnable(document.getElementById('<%= view_req_pixelwidth.ClientID %>'), true);
        ValidatorEnable(document.getElementById('<%= view_req_pixelheight.ClientID %>'), true);
        ValidatorEnable(document.getElementById('<%= view_req_name.ClientID %>'), true);
        ValidatorEnable(document.getElementById('<%= view_req_title.ClientID %>'), true);
        ValidatorEnable(document.getElementById('<%= view_req_description.ClientID %>'), true);
    }
    if (value == '' || value2 == '' || value3 == '' || value4 == '' || value5 == '') {
        alert("Please enter the missing fields");
        return false;
    }
    else if (document.layers || document.all || document.getElementById) {
        return checknumber();                            
    }



    <asp:Button ID="view_btn_save" Text="Save" OnClick="view_btn_save_click"
    OnClientClick="return Validate_view(); "
}

1 个答案:

答案 0 :(得分:2)

if ((anum.test(x)) && (anum.test(y)) && (anum.test(z)) && (anum.test(a)) && (anum.test(b)) && (anum.test(c)))
    testresult = confirm('save change?');
    if(testresult == 0)
    {
        //cancel
        //window.location.reload(true);
        window.location.href=window.location.href;
    }
else {
   alert("Please input a valid number!")
   testresult = false
}