簡體   English   中英

從CodeBehind調用Javascript函數並返回值

[英]Calling Javascript Function From CodeBehind And Return Value

我有一些看起來像這樣的代碼,全部在代碼后面...

var script = "confirm('Would you like to close this order?')";
ClientScript.RegisterStartupScript(typeof(Page), "CloseOrder", script, true);

如何獲得用戶在下一行中單擊是還是否的值? 當此腳本觸發時,是否有可能返回值並繼續在后面的代碼中的下一行?

var script = function(){
    var choice = confirm('Would you like to close this order?');
    if(choice){
        //If the user clicks yes
    }else{
        //If the user clicks no
    }
}
ClientScript.RegisterStartupScript(typeof(Page), "CloseOrder", script, true);

此處的簡單示例: http : //jsfiddle.net/ChaseWest/W569P/

更改: var script = "confirm('Would you like to close this order?')";

至: var script = confirm('Would you like to close this order?');

根據確認彈出窗口的是或否,這會將true或false保存到腳本中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM