0

質問があります。質問を理解するには、次のコードを参照してください。(次の html コードから '<' と '>' の文字を削除しました。そうしないと html タグが表示されないため、タグ名のみを記述しました)

<div>
    <div>
       <img />
       <img />
       <img />
       <img />
    </div>
</div>

jQueryの助けを借りて次のタスクを解決したい

  1. 内側の div の間の 4 つの img から準備が整ったドキュメントでは、最初の img のみが表示され、残りの 3 つの img は非表示になります。
  2. フォーカス、クリックなどの特定のイベントで、内側の div の間の 4 つの img のうち、表示されている img が非表示になり、他の 1 つが表示されるはずです。

その他の質問:

  1. jQuery は他のタグで囲まれた要素だけを識別できますか?

  2. また、jQuery での制御の流れを知りたいですか? 特に連鎖関数で。EX用。

    1. $(selector).fun1(val,{fun2(){ }} 上記の例では、どの関数が最初に実行され、どの順序で実行されますか。

    2. $(selecter).fun1().fun2().fun3() 上記の例では、どの関数が最初に実行され、どの順序で実行されますか。

    3. 関数チェーンの関数はどの順序で実行されますか?

皆さんの返事を待っています!

4

1 に答える 1

1

私がここでやったようなことを試してください。


最初の画像 (twitter) は、要件に従って変更されません。影響を受ける唯一の画像は、クラスを持つ div 内の画像ですsample

HTML

<img src="https://s3.amazonaws.com/twitter_production/a/1265328866/images/twitter_logo_header.png"/>

<input type="text"/>
<input type="text"/>
<input type="text"/>
<input type="text"/>

<div class="sample">
  <img src="http://sstatic.net/so/img/logo.png">
  <img src="http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif">
  <img src="http://cacm.acm.org/images/logo.ACM.gif">
  <img src="http://static03.linkedin.com/img/logos/logo_linkedin_88x22.png">
</div>

JavaScript

$(function () {
    var textboxes = $("input:text"), //gets all the textboxes         
        images = $(".sample img");   //gets all the images

    images.not(":first").hide(); //hide all of them except the first one
    textboxes.each(function (i) {
        var j = i;
        $(this).focus(function () {
            images.hide().eq(j).show();
        });
    });
});
于 2010-02-05T12:25:18.873 に答える