Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击相应图像时,如何在不更改图像位置的情况下在其下方显示文本?_Javascript_Jquery_Html - Fatal编程技术网

Javascript 单击相应图像时,如何在不更改图像位置的情况下在其下方显示文本?

Javascript 单击相应图像时,如何在不更改图像位置的情况下在其下方显示文本?,javascript,jquery,html,Javascript,Jquery,Html,我有图像显示在旁边,当我点击一个特定的图像,它的描述应该出现在下面,而不改变其他图像的位置。我的代码是: <div class="team"> <h3>OUR TEAM</h3> <div class="toggle" style="display:inline-block;"> <a href="#"><img src="http://imgur.com/gallery/I7kTE" width="20" hei

我有图像显示在旁边,当我点击一个特定的图像,它的描述应该出现在下面,而不改变其他图像的位置。我的代码是:

<div class="team">
  <h3>OUR TEAM</h3>
  <div class="toggle" style="display:inline-block;">
    <a href="#"><img src="http://imgur.com/gallery/I7kTE" width="20" height="15"/></a> 
    <h4>name1</h4>
  </div>
  <div class="content">
    Img 1 description texttexttexttexttexttexttexttexttext
  </div>
  <div class="toggle" style="display:inline-block;">
    <a href="#"><img  src="http://imgur.com/gallery/I7kTE" width="20" height="15"/></a> 
    <h4>name2</h4>
  </div>
  <div class="content">
    Img 2 description texttexttexttexttexttexttexttexttext
  </div>
  <div class="toggle" style="display:inline-block;">
    <a href="#"><img src="http://imgur.com/gallery/I7kTE" width="20" height="15"/></a> 
    <h4>name3</h4>
  </div>
  <div class="content">
    Img 3 description text text text text text text text text
  </div>
</div>

将JavaScript代码替换为:

$(document).ready(function () {
    var $content = $(".content").hide();
    $(".toggle").click(function (e) {
        $(this).toggleClass("expanded");
        $(this).next().slideToggle();
    });
});
或者使用JQuery 1.7或更高版本

检查以上链接以获取参考。。。。其他代码从上面的链接获取

HTML


在您的小提琴上,您使用的是jQuery 1.6—在使用.on时,您需要使用jQuery 1.7或更高版本,否则您将需要使用.delegate,而不是.on—如果您使用的是较低版本的jQuery。一旦我选择了一个更高版本的jQuery,你的代码就正常了。检查这个,把你的js文件改成1.7或更高版本,或者使用。单击函数{…}谢谢你的回答,但是我还有一个问题。当我单击一个图像时,其余两个图像在显示信息时向下移动。是否可以在不改变图像位置的情况下显示信息?谢谢您的回答。当我单击图像时,如何使其他图像在显示信息时保持其位置?如何在不移动图像位置的情况下显示信息?这只是我需要的信息的一半。不管怎样,我正在点击正确的标记。但是如果你对如何解决这个问题有任何想法,请告诉我。解决方法是将你的图片和描述放在单独的部分。是的,你可以使用开关盒@Amy img和descripton在不同的部门。我不明白你的意思。你能详细说明一下吗?非常感谢!我正在努力使用$this.next.text在新的div中显示它。您的解决方案更简单、更精确。
$(document).ready(function () {
    var $content = $(".content").hide();
    $(".toggle").click(function (e) {
        $(this).toggleClass("expanded");
        $(this).next().slideToggle();
    });
});
  <div class="list-group">
  <a href="#section-1" id="section-1" class="list-group-item">img 1 </a>
  <a href="#section-2" id="section-2" class="list-group-item">img 2</a>
  <a href="#section-3" id="section-3" class="list-group-item">img 3</a>
  </div>

   <div class='hide section-1'>1</div>
   <div class='hide section-2'>2</div>
   <div class='hide section-3'> 3</div>