0

ユーザーが 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がiframeにある場合、データを取得するにはどうすればよいですか?

4

1 に答える 1

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

それが役に立ったことを願っています!

于 2012-08-26T10:15:27.343 に答える