2012-03-06 32 views
0

我正在使用Uploadify進行文件上傳,並希望在用戶取消上傳時顯示「是/否」對話框。我嘗試了以下,但它不顯示對話框。任何想法下面的代碼有什麼問題?取消文件上傳時的是/否對話框

'onCancel': function (event, ID, fileObj, data) {     
       var x = "Are you sure you want to take this action"; 
       $('<div>' + x + '</div>').dialog({ 
        resizable: false, 
        autoOpen: true, 
        buttons: { 
         "Yes": function() { 
          alert('action taken'); 
          $(this).dialog("close"); 
         }, 
         Cancel: function() { 
          $(this).dialog("close"); 
         } 
        } 
       }); 

任何建議/指針將不勝感激!

+1

工作,我相信'Cancel'應在引號''Cancel'' – elclanrs 2012-03-06 22:23:51

+0

@elclanrs爲什麼呢? '({取消:「它的工作原理」})'效果很好。 – kirilloid 2012-03-06 22:29:06

+0

你有沒有至少包括js文件(可能,jquery-ui)的'dialog'? – kirilloid 2012-03-06 22:29:51

回答

0

試試這個:

var onCancel = function (event, ID, fileObj, data) {     
      var x = "Are you sure you want to take this action"; 
      $('<div>' + x + '</div>').dialog({ 
       resizable: false, 
       buttons: { 
        "Yes": function() { 
         alert('action taken'); 
         $(this).dialog("close"); 
        }, 
        "Cancel": function() { 
         $(this).dialog("close"); 
        } 
       } 
      }); 
     } 
+0

不起作用。該函數未被調用。 – GoldenUser 2012-03-06 22:28:43

+0

你的意思是'onCancel'函數沒有被調用? – 2012-03-06 22:43:58

+0

正在調用onCancel,但其中沒有任何內容。 – GoldenUser 2012-03-06 22:54:36

0

爭取你的按鈕以下代替:

buttons: [{ 
    text: 'Yes', 
    click: function() { 
     alert('action taken'); 
     $(this).dialog("close"); 
    }},{ 
    text: 'Cancel', 
    click: function() { 
     $(this).dialog("close") 
    }}] 
+0

這也行不通... – GoldenUser 2012-03-06 22:53:09

0

你追加新創建div到HTML的body

嘗試:

onCancel: function (event, ID, fileObj, data) { 
    var x = "Are you sure you want to take this action"; 
    var dlg = $('<div />').attr('id', 'RUSure').text(x).dialog({ 
     autoOpen: true, //Make sure it opens automatically. 
     resizable: false, 
     buttons: { 
      "Yes": function() { 
       alert('action taken'); 
       $(this).dialog("close"); 
      }, 
      "Cancel": function() { 
       $(this).dialog("close"); 
      } 
     } 
    }) 
    $('body').append(dlg); 
    $('#RUSure').dialog('open'); 
    //dlg.dialog('open'); //or this, maybe? 
+0

不。爲什麼我需要這樣做? – GoldenUser 2012-03-06 22:53:56

+0

'$('

' + x + '
')'創建一個未連接到DOM的新div。 AFAIK,您需要將它附加到DOM上才能真正顯示,以便用戶可以與它進行交互。將它包裝在'$('body')。append();'將其附加到HTML的'body'中。你可能還需要給它一個'id',並在之後調用'$(id).dialog('open');'。 – pete 2012-03-06 22:56:57

+0

謝謝。你能告訴我我應該把這段代碼放在上面的函數中嗎? – GoldenUser 2012-03-06 23:03:04

0
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" /> 
<script src="http://code.jquery.com/jquery-1.8.2.js"></script> 
<script src="/resources/demos/external/jquery.bgiframe-2.1.2.js"></script> 
<script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script> 
<link rel="stylesheet" href="/resources/demos/style.css" /> 
<script type="text/javascript"> 
    $(document).ready(function() { 
     $('#cmdShowDialog').click(function (event) { 
      event.preventDefault(); 
      var $dialog = $('<div>Dynamic Dialog with Buttons.</div>') 
      .dialog 
      ({ 
       title: 'Cancel', 
       width: 300, 
       height: 200, 
       buttons: 
       [{ 
        text: "Ok", 
        click: function() { 
         $dialog.dialog('close'); 
        } 
       }, 
       { 
        text: "Cancel", 
        click: function() { 
         $dialog.dialog('close'); 
        } 
       }] 
      }); 
     }); 
    }); 
</script> 


<div> 
    <asp:Button ID="cmdShowDialog" runat="server" Text="Show Dialog" /> 
</div> 

嘗試,這將肯定

相關問題