doushan5222 2017-02-24 09:16
浏览 94

一次jQuery多个动作

I'm trying to make some sense with jQuery, but since I never worked with javascript I'm having a bit of trouble.

Basically what am I trying to do.

I have this bit of code:

<div>    
  <a href="#"> Text 1 </a>
</div>
<div class="col-sm-5">
  <span class="text show" style="display: none">sometext</span>
  <img src="someimage.png">
</div>

and I would like to change it to the following:

<div>    
  <a href="#"> Text 1 CHANGED</a>
</div>
<div class="col-sm-5">
  <span class="text show">sometext</span>
  <img src="someimage.png" style="display: none>
</div>

after clicking on link with "text 1".

List of changes: Change link text switch image for text and the other way

Every time I click the link it is supposed to switch to the other variation, back and forward.

I have already tried some sollutions I found, mainly javascripts, but since I never worked with them I wasn't able to make it work.

http://jsfiddle.net/j999y/2362/

  • 写回答

1条回答 默认 最新

  • dqxboe2628 2017-02-24 09:33
    关注

    There are many ways of doing what you want to do, but the most direct is probably something like this:

    $('.text').click(function() {
      $('.text.show').toggle();
      $('.image').toggle();
      $(this).text('Text 1 CHANGED');
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div>    
      <a href="#" class="text">Text 1</a>
    </div>
    <div class="col-sm-5">
      <span class="text show" style="display: none">sometext</span>
      <img class="image" src="https://lh3.googleusercontent.com/L8b2jHW8ttKu2spXcN6yUjocE_yIBG3E-bBot66cUOj_KsVCm6WcW5A-mxkKM4al6FI=w300-rw">
    </div>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图