Javascript 在手风琴中区分展开/折叠单击
我已将点击绑定到标题。有没有办法区分单击是扩展当前标题还是折叠当前标题Javascript 在手风琴中区分展开/折叠单击,javascript,jquery,bind,accordion,Javascript,Jquery,Bind,Accordion,我已将点击绑定到标题。有没有办法区分单击是扩展当前标题还是折叠当前标题 $('.acord h3').bind('click', function (e) { // bind to the the header / anchor clicks //need way to differentiate between expanding/collapsing click here //only do below if it is expanding. e.sto
$('.acord h3').bind('click', function (e) {
// bind to the the header / anchor clicks
//need way to differentiate between expanding/collapsing click here
//only do below if it is expanding.
e.stopPropagation();
var x=(this);
alert(x.getElementsByTagName("A")[0].getAttribute("href"));
});
您可以使用
类
或数据
-属性来检测,例如
var $el = $(this);
var isOpened = $el.hasClass('open'); // or check some data-attribute
$el.toggleClass('open', !isOpened);
你是说slideToggle()?
var x=(这个)代码>-什么?通常不展开H3
元素,而是展开下面的相关DIV。您的代码的HTML示例会有所帮助。