2012-08-26 3 views
0

사용자가 iframe에서 입력 한 양식 데이터를 읽으려면 어떻게해야합니까? JQuery와를iframe에서 양식 데이터 읽기

<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와 :

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 iframe이없는

, 내가 이런 일을 할 것

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

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

}); 

지금 html 인 경우 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 

내가 도움이 희망을!