如何获取所选确认框的值:
我有这段代码:
string scriptString = "<script language='JavaScript'> ";
scriptString += "confirm ('Are you sure you want to Close this period.')";
scriptString += "</script>";
Response.Write(scriptString);
有没有办法确定你选择是或否?
答案 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
}
答案 2 :(得分:0)
您应该将确认结果存储在隐藏字段值中,如下所示:
if (confirm("Are you sure you want to proceed?")==true){
hiddenField.value = 'true';
return true;
} else {
hiddenField.value = 'false';
return false;
}
然后从C#
中获取隐藏字段的值