2012-08-26 42 views
0

如何讀取用戶從iframe輸入的表單數據?從iframe讀取表單數據

沒有的iframe,我會做這樣的事情:

jQuery的:

function getRowData(id, parent){ 
    var data = []; 
    $(parent+' table tr').each(function(){ 
     var row = {}; 
     $(this).find('select, input, textarea').each(function(){ 
      if(($(this).attr('id') == id) && (typeof $(this).attr('name') !== 'undefined' && $(this).attr('name') !== false)){ 
       row['id'] = id; 
       row[$(this).attr('name')] = $(this).val(); 

      } 
     }); 
     data.push(row); 
    }); 
    return data; 
} 

和HTML:

<table id="form-table"> 
<td><input type="checkbox" name="n_available" checked="checked"></td> 
<td><input type="checkbox" name="n_oem" checked="checked"></td> 
</table> 

,並調用了jQuery:

$('.get-data').live('click', function() { 
    postData = $(this).attr("id"); 

    getRowData("form-table", $(this).attr("id");//here i have my form in an array... 

}); 

現在,如果html i在iframe中,我如何獲取數據?

+0

iframe頁面是否來自同一個域? – Chris

+0

是的,它來自同一個域 – tom91136

回答

2

您可以訪問iframe的內部文件,並使用該語法元素:

$("#your_iframe_id").contents().find("body"); //this returns the body of the iframe 
$("#your_iframe_id").contents().find("#form-table"); //this returns the table form-container inside the iframe 

我希望幫助!