Jquery点击图片切换 [英] Jquery Toggle on click of image

查看:51
本文介绍了Jquery点击图片切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解jquery切换的工作原理。我想在点击带有 go_down 类的图像时切换到类 plr-anchor 的下一个锚点。数据使用地图填充。

I am trying to understand how the jquery toggle works. I want to toggle to next anchor with class plr-anchor on click of image with class go_down. The data is populated using maps.

Jquery代码:

$('.go_down').on('click',function(e){
    #('.plr-anchor').next('.plr-anchor').toggle()});
}

代码段:

{data.map(function(categ) {
return <div>
<a className="plr-anchor" id={categ.short_name}></a>
<img src="/static/img/icon_up.png" className="go_down"/>
</div>}.bind(this)}

Jquery调用函数的语法似乎有问题。我是Jquery的新手,任何帮助都会很棒。提前致谢。

There seems to be a problem with the syntax on the Jquery call function. I am newbie with Jquery, any help will be great. Thanks in advance.

推荐答案

您使用过而不是 $ 内部点击处理程序。你还需要找到确切的 plr-anchor 这是在点击之前现在你正在切换所有 plr-anchor

You have used # instead of $ inside click handler. Also you need to find exact plr-anchor which is before the clicked image. Right now you are toggling all plr-anchor.

对于动态元素,请使用 $(document).on(event,selector,function(){}); 用于绑定点击处理程序。请参阅下面的代码

For dynamic elements, use $(document).on(event, selector, function(){}); for binding click handlers. See below code

$(function(){
  $(document).on('click','.go_down',function(e){
     $(this).prev('.plr-anchor').toggle();
  });
});

这篇关于Jquery点击图片切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆