问题
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();
});
回答1:
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();
来源:https://stackoverflow.com/questions/1322198/using-variables-in-rel-attribute-in-jquery-selector