Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在手风琴中区分展开/折叠单击_Javascript_Jquery_Bind_Accordion - Fatal编程技术网

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示例会有所帮助。