jquery - 左侧菜单切换图像

标签 jquery css html

我有以下代码。

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
      <title>slide demo</title>
         <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
      <style>
        #toggle {
          width: 100px;
          height: 100px;
          background: #ccc;
        }
       </style>
 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
 <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
</head>
<body>
 <button id="mybutton">Show/Hide Left Slide Menu</button>
 <div id="toggle"></div>

   <script>
    $('#mybutton').click(function () {
        $("#toggle").toggle("slide");
    });
</script>

   </body>
 </html>

我想显示一张图片(image1)。当用户点击 image1 时,div 应该出现,image1 应该隐藏,image2 应该出现。当用户点击 image2 时,div 应该隐藏,image2 应该隐藏,image1 应该出现。我怎样才能做到这一点?

最佳答案

尝试使用这个

http://jsfiddle.net/AmqcY/

$(document).ready(function(){
$(document).on('click','#imageid',function(){

var $this= $(this);
$('#toggle').toggle('slide',function(){
  //swap src of the image on toggle is completed
  var imgsrc = $this.attr('src');
  $this.attr('src',$this.data('othersource'));
  $this.data('othersource',imgsrc);
});
   });
  });

关于jquery - 左侧菜单切换图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18462727/

相关文章:

javascript - 如何获取包含表单中可用的所有输入标签的列表

javascript - jQuery:如何正确暂停递归?

javascript - 如何在 jQuery 插件中创建全局对象?

html - CSS动画——让图片一张一张淡入淡出

html - 我如何告诉我的 HTML 两个元素应该占据剩余可用宽度的其余部分?

javascript - jQuery 根据特定文件夹设置的间隔淡入不同的主体背景图像

Html 上下索引

javascript - float : right is messing up the order

html - 无法在 div 中居中 ul

html - 我正在自动填充 CSS