2010-07-05 122 views
3

我一直在嘗試這種整天...打開一個jQuery對話框從主窗口的IFRAME

我有一個形式在iframe中,這包含了表單驗證JQuery驗證。我只想當數據無效時,jquery對話框出現在主頁面,出現在top.document中。

這是我上的iframe代碼:

​​

,這是一段代碼,應該啓動的對話框:

$("#search-form").validate({ 

     rules: { datapicker: {required: true,dateDE: true}}, 
     debug: true, 
     messages: { 
     datapicker: { 
      required: "És necessari introduïr una data", 
      date: "S'ha d'afegir una data correcte: dd/mm/aaaa" 
     } 
     }, 
     errorPlacement: function(error, element) { 
       error.prependTo($('#dialog-message', top.document)); 
     }, 
     errorLabelContainer: $("#dialog-message ul", top.document), 
     showErrors: function() { 
      $('#dialog-message',top.document).dialog('open'); 
      this.defaultShowErrors(); 
     } 
}); 

所以......這不工作,..如果我試試這個指令一切工作正常

$("#dialog-message", top.document).css(...) //works fine! 

我想可能是有一些問題,選擇$ -top.document和直徑日誌功能...或者可能是不可能使用對話框()爲div在不同的幀...

請幫助! :d

在此先感謝

+0

@webarto,您的評論是沒有意義的 - 爲什麼jQuery不適用於使用iframe時? – Kon 2011-03-27 01:51:09

+0

......我不小心投了評論......呃,白癡。 – Kon 2011-03-27 01:51:51

+0

沒有進一步的問題,您的榮譽。 – 2011-03-27 01:54:14

回答

2

有在iframe的代碼引用父,並調用父類的JavaScript函數,這樣的事情:

// in iframe code: 
parent.doSearchFormValidate(); 

// parent page has definition for doSearchFormValidate(). 
function doSearchFormValidate() { 
    $("#search-form").validate({ 
    ... 
    }); 
} 
相關問題