0

jquery と ajax について質問があります

2つのhtmlファイルと1つのjsがあります

index.html

<h1><div id="parent_header">This is parent header</div></h1>

<button id="my_button">Click here to load child.html</button>

<div id="result"></div>

child.html

<button id="child_button">This button should change parent header</button> <p />

ここで、index.html の my_button で child.html を開き、それを結果の div にロードします。

$(document).ready(function() {
$("#my_button").click(function() {
    $.ajax({
        url: "child.html",
        dataType: "html",
        success: function(result) {
            $("#result").html(result);
        }
    });
});
});

成功しました。ここで、child.html の child_button が index.html の親ヘッダーを変更するようにします。ajax-loaded-content がそれを呼び出したドキュメント内の何かを変更する方法は? (iframe を使用していません)

デモ: http://www.lobart78.byethost24.com/ (jsfiddle では不可)

ありがとうございました

4

1 に答える 1

1
$(document).ready(function() {
$("#my_button").click(function() {
    $.ajax({
        url: "child.html",
        dataType: "html",
        success: function(result) {
            $("#result").html(result);
            $("#child_button").on("click",function() { $("#parent_header").html("just changed for horror!"); });
        }
    });
});
});
于 2013-05-05T17:02:53.507 に答える