在jquery选择器中的rel属性中使用变量 [英] using variables in rel attribute in jquery selector

查看:132
本文介绍了在jquery选择器中的rel属性中使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用rel属性将div匹配到按钮.我在相应的div的rel字段中使用按钮的ID.有多个按钮.单击按钮时,我想使用show()方法显示相应的div,并隐藏其他div.按钮工作正常,但div没有响应.我的直觉说我没有正确格式化选择器.谢谢.

I'm using the rel attribute to match a div to a button. I use the button's id in the corresponding div's rel field. There are multiple buttons. When a button is clicked I want to show the corresponding div with the show() method, and to hide the other divs. The buttons work fine, but the divs are not responding. My gut says I'm not formatting the selector properly. Thanks.

    $("div.media_button").click(function (){

   var relid = this.id;

   $("div.media_button").not(this).fadeTo("normal",0.33);
   $(this).fadeTo("normal",1);
   $("div.media_selection[rel!='" + relid + "']").hide();
   $("div.media_selection[rel='" + relid + "']").show();   
 });

推荐答案

您不需要单引号.您是否可以粘贴标记,以防万一以下内容无法正常工作.

You do not need the single quotes. Can you paste the markup just incase the below doesnt end up working.

$("div.media_selection[rel=" + relid + "]").hide();
$("div.media_selection[rel=" + relid + "]").show();  

这篇关于在jquery选择器中的rel属性中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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