2013-08-29 25 views
2

我加載一個對話框,一個divJQuery用戶界面對話框重裝原始內容

<div id="dialog-message" title="Send Message" style="display: none;"> 
<form id ="form_message"> 
<textarea name="message_field" id="message_field" rows="8" cols="62" class="ui-widget-content ui-corner-all" style="resize: none;"></textarea> 
</form> 

創建對話框中的$(document)內。就緒(函數()打開它使用的鏈接。 在提交對話框的更改與返回消息對話框的內容,用戶可以關閉該窗口。

// dialog create 
$("#dialog-message").dialog({ 
autoOpen: false, 
resizable: false, width: 520, height: 320, 
modal: true, 
buttons: {"Send": { text: "Send", id: "btn_send", click: function() {}, 
close: function() {if($('#form_message').length) {$(this).find('form')[0].reset();} } 
}); 

//link to open dialog 
$('#dialog_link').click(function(){$("#dialog-message").data("msg_data", {msg_from: 14, msg_to: 15}).dialog("open"); return false; }); 

//operations made on submit dialog 
$('#btn_send').hide(); 
$('#dialog-message').html(data.error); 

這個問題我有是,一旦你再次打開該對話框,返回消息仍然存在,並且它的沒有加載原始div內容 ho我可以做到這一點?我試圖在關閉事件中銷燬對話框,但隨後對話框根本沒有重新打開。

+0

你可以張貼的JavaScript您用來設置對話框的內容?另外,爲什麼在表單的id中會出現charactesr? –

+0

我更新了原來的帖子,我刪除了轉義字符,但我忘了一些,我從php創建JS – Hulud

回答

2

只保存消息字段的內容你改變它之前....這樣的:

var message_field_html = ""; 

function openDialog(){ //or whatever function calls your dialog 
    if(message_field_html != ""){ 
     $('#dialog-message').html(message_field_html); 
    } 
    //do things 
} 

function changeDilogText(){ //or whatever function changes the text 
    message_field_html = $('#dialog-message').html() 
    $('#dialog-message').html(data.error); 
} 

[編輯]編輯的代碼馬赫你的問題

+0

作品像一個魅力,非常感謝 – Hulud

+0

真棒解決方案。解決了我的問題。 –

相關問題