是否有任何方法可以将click事件附加到多个元素,然后将所有子元素都添加到该元素中,除了THIS(单击一个)的子元素以运行函数?
这是一个可怕的解释,但我正在寻找这样的事情:
$(".block_header").click(function(){ $(".block_header span:not(this span)").toggleClass("collapse expand"); $(".container:not(this+div.container)").slideToggle(); });
这是一个示例HTML:
<h3 id="sender_header" class="block_header"><span>Sender</span></h3> <div id="sender_container" class="container"> <p>Show or hide this,based on which H3 is clicked.</p> </div> <h3 id="receiver_header" class="block_header"><span>Receiver</span></h3> <div id="receiver_container" class="container"> <p>Show or hide this,based on which H3 is clicked.</p> </div> <h3 id="delivery_header" class="block_header"><span>Delivery</span></h3> <div id="delivery_container" class="container"> <p>Show or hide this,based on which H3 is clicked.</p> </div> <h3 id="items_header" class="block_header"><span>Items</span></h3> <div id="items_container" class="container"> <p>Show or hide this,based on which H3 is clicked.</p> </div> .... etc,etc (many more of the same)
希望这不是太复杂.它会省去很多代码.