2010-02-05 72 views
0

我有问题请参考下面的代码来理解这个问题。 (我删除“<”,然后从下面的HTML代码“>”字符,因为否则的HTML标记不会,所以我写了唯一的标记名称是可见的)如何识别由其他元素或标签包围的组元素?

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

我要解决以下的帮助下任务jQuery

  1. 在文档准备出来的四个img之间的内部div只有第一个img应该是可见的,其余的三个img应该隐藏。
  2. 现在关注焦点等特殊事件,点击等内部div之间的四个img可见img get hide,另一个应该可见。

一些其他问题:

  1. 是jQuery是能够识别只能通过其他标签包围的元素?

  2. 我也想知道如何在jQuery控制流?特别是链式功能。 EX的 。

    1. $(selector).fun1(val,{fun2(){ }}在上面的例子中 是GET第一和以什么顺序执行哪个功能。

    2. $(selecter).fun1().fun2().fun3() 在上面的例子中,哪个函数首先被执行,以什么顺序执行。

    3. 函数链中的函数按什么顺序执行?

等待你的答复家伙!

+2

你应该修改你原来的问题(HTTP div中的://计算器。 com/questions/2206898/how-can-i-write-jquery-for-below-problem),而不是打开一个新的。 – 2010-02-05 12:27:37

回答

1

尝试像我这样做here


第一张图片(twitter)不会根据您的要求更改。受影响的唯一图像是在具有类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(); 
     }); 
    }); 
}); 
+1

谢谢朋友的回复。您的解决方案对我来说非常有用。再次感谢! – 2010-02-05 12:45:12

相关问题