简体   繁体   English

如何使用jquery选择“向上钻取”按钮,以便可以执行on click事件?

[英]How to select the drillup button using jquery, so I can do an on click event?

I am using highcharts, the pie-drilldown one. 我使用的是高位图表,即细分图表。 I created three buttons outside of the div my highchart is in and when a pie slice is clicked it hides the three buttons, but I want the three buttons to reappear when the drill up button is clicked using jquery. 我在highchart所在的div之外创建了三个按钮,当单击饼图时,它隐藏了三个按钮,但是我希望当使用jquery单击向上钻取按钮时,这三个按钮重新出现。 If there is a way to do it without jquery I'm open to that idea too. 如果有没有jquery的方法,我也愿意接受这种想法。

var $button0 = $('#button0');
var $button1 = $('#button1');
var $button2 = $('#button2');
$('tspan[class=highcharts-text-outline]').click(function () { // WORKS
    $button0.hide(); $button1.hide(); $button2.hide();
    .
    . Other code that doesn't matter
    .
});

$('#highcharts-lb5nb7e-2 > svg > g.highcharts-button.highcharts-drillup-button.highcharts-button-normal').click(function (){ // DOESN'T WORK

    $button0.show(); $button1.show(); $button2.show();
    alert("AM I BEING CALLED?!");
});

Thank you 谢谢

You can use events of highcharts for show and hide of buttons 您可以使用高图事件来显示和隐藏按钮

 chart: {
    type: 'pie',
    events:{
        drilldown:function(){
        var butonsElems=document.getElementsByTagName('button')
        for(var i=0;i<butonsElems.length;i++){
            butonsElems[i].style.display='none'
        }
      },
      drillup:function(){
        var butonsElems=document.getElementsByTagName('button')
        for(var i=0;i<butonsElems.length;i++){
            butonsElems[i].style.display=''
        }
      }
    }
},

Fiddle Demonstration 小提琴示范

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM