2014-09-03 45 views
0

我经常沿着经典ASP以下行用过的东西:访问的Javascript确认结果从传统的ASP

Response.Write "<script type=""text/javascript"">alert('Hello world')</script>" 

,但我会怎样做JavaScript的确认声明类似的事情和结果返回给我的VB询问结果?

Response.Write "<script type=""text/javascript"">confirm('Do you want to continue?')</script>" 

显然是不够的。如果可能,我需要将结果分配给一个变量。

在此先感谢。

+1

你不能直接这样做。您将不得不使用AJAX将用户响应发送到服务器,然后可能会解析服务器在客户端代码中的响应。 – 2014-09-03 13:13:10

回答

1

我会使用window prompt()方法。下面是从W3学校为例:

<html> 
<body> 

<p>Click the button to demonstrate the prompt box.</p> 

<button onclick="myFunction()">Try it</button> 

<p id="demo"></p> 

<script> 
function myFunction() { 
    var person = prompt("Please enter your name", "Harry Potter"); 
    if (person != null) { 
     document.getElementById("demo").innerHTML = 
     "Hello " + person + "! How are you today?"; 
    } 
} 
</script> 

</body> 
</html> 

我用从W3上面的例子中捕获输入,只能采取价值,并提交到服务器:

document.getElementById("demo").value= 
     person 
document.submit()