从确认框中获取价值

时间:2011-02-08 23:10:42

标签: c# javascript asp.net popup

如何获取所选确认框的值:

我有这段代码:

string scriptString = "<script language='JavaScript'> ";
scriptString += "confirm ('Are you sure you want to Close this period.')";
scriptString += "</script>";
Response.Write(scriptString);

有没有办法确定你选择是或否?

3 个答案:

答案 0 :(得分:1)

var x = confirm('...')
alert(x)

string scriptString = "<script language='JavaScript'> ";
scriptString += "var x = confirm ('Are you sure you want to Close this period.')";
scriptString += "alert(x)";            
scriptString += "</script>";
Response.Write(scriptString);

答案 1 :(得分:1)

确认返回一个布尔值,表示确定或取消(true表示确定,false表示取消)。

你可以像这样使用它:

if(confirm ('Are you sure you want to Close this period.')) {
  //they clicked ok
}
else {
  //they clicked cancel
}

在此处详细了解:https://developer.mozilla.org/En/DOM/Window.confirm

答案 2 :(得分:0)

您应该将确认结果存储在隐藏字段值中,如下所示:

if (confirm("Are you sure you want to proceed?")==true){
    hiddenField.value = 'true';
    return true;
} else {
    hiddenField.value = 'false';
    return false;
}

然后从C#

中获取隐藏字段的值
相关问题