2015-05-22 19 views
0

我能夠插入我的對話框。但我無法顯示它。使用JS文件顯示JQuery對話框

這是我如何插入:

if ($("#dialogSendMail").length) { 

} 
else { 
    $("#DeltaPlaceHolderUtilityContent").after("<div id='dialogSendMail' title='Enter mail body'> <label for='mailBody'>Type the text you want to display in the email:</label><p><input type='text' id='mailBody' name='mailBody'></p></div>"); 
} 

這就是我如何努力,以顯示它:

var answer =""; 

$("#dialogSendMail").dialog({ 
     resizable: false, 
     height:350, 
     width:650, 
     modal: true, 
     autoOpen : false, 
     buttons: [ 
      { 
       text: "Send Mail", 
       click: $.noop, 
       type: "submit", 
       form: "myForm" 
      }, 
      { 
       text: "Close", 
       click: function() { 
        $(this).dialog("close"); 
       } 
      } 
     ] 
    }); 

但是當我運行我的代碼,它不會顯示該對話框。此外,我試圖找到一種方法來獲取文本框的響應。

任何人都可以幫助我嗎?

另見:JQuery dialog as input

在我的js文件我也有如下一行:

answer = GetEmailBody(); 

完GetEmailBody()調用你看上漲,顯示該對話框的方法。

我的代碼現在看起來如下:

function GetEmailBody() { 
    $("#dialogSendMail").dialog({ 
     resizable: false, 
     height: 350, 
     width: 650, 
     modal: true, 
     autoOpen: true, 
     buttons: [ 
      { 
       text: "Send Mail", 
       click: function() { 
        $(this).dialog("close"); 
        answer = "This is just a test message."; 
        SendEmail(); 
       } 
      }, 
      { 
       text: "Close", 
       click: function() { 
        $(this).dialog("close"); 
        SendEmail(); 
       } 
      } 
     ] 
    }); 

} 

function SendEmail() 
{ 
    xmlHttpReq.open("GET", _spPageContextInfo.siteServerRelativeUrl + "/_layouts/SendDocuments/MyCustomHandler.ashx?ItemsArray=" + fileRefArray + "&IdsArray=" + idArray + "&EmailText=" + answer, false); 
    xmlHttpReq.send(null); 

    var yourJSString = xmlHttpReq.responseText; 
    alert(yourJSString); 
} 

但現在我得到一個應用程序應該在我的電腦上打開的消息。 當我沒有通過對話時,這不是必需的。 然後它打電話給我發送郵件的ASHX文件。

+1

您需要將事件綁定到該事件。 –

+0

我認爲沒有真正的事件。 我在SharePoint中做它。在那裏點擊一個按鈕,我需要發送一封電子郵件。該對話框在那裏,用戶可以輸入附加信息添加到電子郵件中。 –

+0

如何將'autoOpen'設置爲true? [演示](https://jsfiddle.net/catsjwzy/1/) – empiric

回答

0

好吧,我能解決我的問題:

功能GetEmailBody(){ $( 「#dialogSendMail」)對話框({ 可調整大小:假, 高度:350, 寬度:650,模態 :真, 的AutoOpen:真, 按鈕:[ { 文字: 「發送郵件」, 點擊:function(){ $(this).dialog(「close」); answer = $(mailBody)[0] .innerText; xmlHttpReq.open(「GET」,_spPageContextInfo.siteServerRelativeUrl +「/_layouts/SendDocuments/MyCustomHandler.ashx?ItemsArray=」+ fileRefArray +「& IdsArray =」+ idArray +「& EmailText =」+ answer,false); xmlHttpReq.send(null);

   var yourJSString = xmlHttpReq.responseText; 
       alert(yourJSString); 
      } 
     }, 
     { 
      text: "Close", 
      click: function() { 
       $(this).dialog("close"); 
       SendEmail(); 
      } 
     } 
    ] 
}); 

}

function SendEmail() 
{ 
    xmlHttpReq.open("GET", _spPageContextInfo.siteServerRelativeUrl + "/_layouts/SendDocuments/MyCustomHandler.ashx?ItemsArray=" + fileRefArray + "&IdsArray=" + idArray + "&EmailText=" + answer, false); 
    xmlHttpReq.send(null); 

    var yourJSString = xmlHttpReq.responseText; 
    alert(yourJSString); 
} 

而這個工程,我希望。

1

設置的AutoOpen爲true:

$("#dialogSendMail").dialog({ 
    resizable: false, 
    height:350, 
    width:650, 
    modal: true, 
    autoOpen : true, 
    buttons: [ 
     { 
      text: "Send Mail", 
      click: $.noop, 
      type: "submit", 
      form: "myForm" 
     }, 
     { 
      text: "Close", 
      click: function() { 
       $(this).dialog("close"); 
      } 
     } 
    ] 
}); 
+0

好吧,自動打開工作。我現在得到我的對話。但我仍然想要檢索我輸入的文本,所以我可以在我的電子郵件中將它用作文本。 –