2012-10-16 38 views
0
$(document).ready(function() { 
     $('.abc').click(function() { 
      var status = $("#<%=ddlstatus.ClientID%>").val; 
      if (status == "Prepared") { 
       var _Action = confirm('Do you really want to cancel this payment ? All pending money will be available in the retention account of the contractor '); 
       if (_Action) { 
        $.blockUI({ css: { 
         border: 'none', 
         padding: '15px', 
         backgroundColor: '#000', 
         '-webkit-border-radius': '10px', 
         '-moz-border-radius': '10px', 
         opacity: .5, 
         color: '#fff' 
        } 
        }); 
        return true; 
       } 
       else { 
        return false; 
       } 


      } 

     }); 
    }); 

当我运行此JavaScript时我收到确定按钮,但我还想添加取消按钮。加上我打电话背后在javascript中添加一个“确定”和“取消”按钮

+3

“但我想添加一个取消按钮以及”?不确认给你一个取消按钮? –

+0

不,我是没有t取消取消按钮 – vini

+0

您还获得了哪些其他按钮? – Ian

回答

2

这从C#代码,你可以尝试使用jQuery UI Dialog

<div id="dialog" title="Confirmation Required"> 
    Do you really want to cancel this payment? All pending money will be available in the retention account of the contractor. 
</div> 

<script type="text/javascript"> 
    $(document).ready(function() { 
    $("#dialog").dialog({ 
     autoOpen: false, 
     modal: true 
    }); 
    }); 

    $(".abc").click(function(e) { 
    e.preventDefault(); 
    var targetUrl = $(this).attr("href"); 
    var status = $("#<%=ddlstatus.ClientID%>").val(); 

    $("#dialog").dialog({ 
     buttons : { 
     "Ok" : function() {    
     if (status == "Prepared") { 
      $.blockUI({ css: { 
        border: 'none', 
        padding: '15px', 
        backgroundColor: '#000', 
        '-webkit-border-radius': '10px', 
        '-moz-border-radius': '10px', 
        opacity: .5, 
        color: '#fff' 
        } 
       }); 
      } 
      window.location.href = targetUrl; 
     }, 
     "Cancel" : function() { 
      $(this).dialog("close"); 
     } 
     } 
    }); 

    $("#dialog").dialog("open"); 
    }); 
</script> 

DEMOhttp://jsfiddle.net/rCVrc/

编辑

引述尼克的回答是here,您可以使用ScriptManager.RegisterStartupScript()方法,像这样:

ScriptManager.RegisterStartupScript(this, GetType(), "modalscript", 
    "$(function() { $('#dialog').dialog({ 
     buttons : { 
     'Ok' : function() {    
     if (status == 'Prepared') { 
      $.blockUI({ css: { 
        border: 'none', 
        padding: '15px', 
        backgroundColor: '#000', 
        '-webkit-border-radius': '10px', 
        '-moz-border-radius': '10px', 
        opacity: .5, 
        color: '#fff' 
        } 
       }); 
      } 
      window.location.href = targetUrl; 
     }, 
     'Cancel' : function() { 
      $(this).dialog('close'); 
     } 
     } 
    }); });", true); 

“如果你不使用一个ScriptManager/UpdatePanel的,使用等效ClientScriptManager版本。

重要的是要记住包裹你的代码中的document.ready处理器(IE浏览器的大多数问题没有它),这样你的元素是很重要的(在我的例子,id="dialog")是在DOM准备好了。”

+0

这可以从c#后面的代码调用吗? – vini

+0

ClientScript.RegisterStartupScript(typeof(Page),“”, ““); – vini

+0

我打电话给后面的代码,但它只显示一个OK按钮 – vini

0

这是一个长镜头,但使用window.confirm()给了confirm()

相关问题