1

次のコードで「メイン」フレームの要素にクリックハンドラーをアタッチさせることはできません。このコードはフレームセット定義に含まれています。

<!-- #include file ="..\include\AuthenticationCheck.asp" --> 
<!-- #include file ="..\include\serverValidate.asp" --> 

<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<title>Raider Writer Student Roll</title>
<script type="text/javascript" src="../include/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../include/js/jquery-ui-1.8.4.custom.min.js"></script>

<script type="text/javascript">

    $(function(){//document ready

       $("#main").ready(function () { //The function below executes once the iframe has finished loading

                  $("#main .confirmLink").click(function(e) {
                    alert('hi');

                    });
                });


} );
</script>

</head>
<%
    course_id=request("course_Id")
    if ValidateNumber(course_id)=false then 
        err.raise 8,"Validation: <course_id> is Invalid","<course_id> is: " & course_id
    End if


%>
<%session("currentpage")="tracking"%>

<frameset rows="100,*" border="0">
  <frame name="banner" id="banner" scrolling="no" target="contents" src="rollbanner.asp?course_id=<%response.write(course_id)%>">
  <frameset cols="16%,*" border="5">
    <frame name="contents" id="contents" src="roll.asp?course_id=<%response.write(course_id)%>">



        <frame name="main" id="main" src="../action/helpread.asp?dm=trackingdocs">

  </frameset>
  <noframes>
  <body>
  <p>This page uses frames, but your browser doesn't support them.</p>

  </noframes>
</frameset>


</body>
</html>
4

3 に答える 3

1

そのようにDOMの内部を見ることはできません<frame>。これを試して:

$('#main').contents().find('.confirmLink').click(function() { ... });

さて、それでも状況によっては問題が発生する可能性があります。フレーム内のページがjQueryインポートする場合は、次のように実行できます。

$('#main').get(0).contentWindow.$('.confirmLink').click(function() { ... });

フレーム自体のjQueryを使用してハンドラーを設定します。

于 2010-09-14T21:32:38.737 に答える
0

#mainコンテキストとして使用してみましたか?

$(".confirmLink","#main").click(function(e) {('hi');});

またはに $("#main").ready(fn)変更$("#main").load(fn)

于 2010-09-14T20:42:07.683 に答える
0

たくさんの調査をしなければ、それはおそらく「ドキュメントの準備ができている」問題だと思います。親ドキュメントを待機していますが、フレームドキュメントは待機していません。親ドキュメントは、そのページのすべての要素が「ロードされた」と見なされます。フレームは技術的にはページの一部ではなく、それ自体がページであるため、フレームとは見なされません。

フレームにロードされたページの制御がある場合、簡単な回避策は、そのjQuery呼び出しを関数にカプセル化してから、フレームのページでその関数を呼び出すことです。

于 2010-09-14T20:45:08.457 に答える