2

iframe の「test」という名前のクラスが親で jquery コードを実行できるようにしたいのですが、次のことを試しましたが、機能しません

親 :

$("#listing").$(".test").click(function() {
  alert($(this).attr('title'));
  return false;
});

iframe <iframe id="listing"> :

<a href="/89" title="hello" class="test">Click</a>
<a href="/90" title="hello2" class="test">Click</a>

私は何をすべきか?ありがとう

4

3 に答える 3

1

これを試して:

$("#listing").find(".test").click(function() {
  alert($(this).attr('title'));
  return false;
});
于 2012-06-06T17:32:46.163 に答える
0

contents()メソッドは、他の用途に加えて、コンテンツ ドキュメントへのアクセスを許可します<iframe>(もちろん、Same Origin Policyにより、親と同じドメインからのものである必要があります)。

$("#listing").contents().find(".test").click(function() {
    alert($(this).attr("title"));
    return false;
});
于 2012-06-06T17:40:04.690 に答える
0

contentWindow.document を使用して iframe ドキュメントにアクセスできます。

$(document.getElementById('listing').contentWindow.document).find('.test').click(function(){...});
于 2012-06-06T17:31:50.577 に答える