单击一个按钮会触发同一个事件两次? Highcharts 图例显示的奇怪行为
Clicking on a button triggers the same event twice? Strange behaviour for Highcharts legend display
我有一个问题,点击一个按钮来显示 Highcharts 图的图例似乎触发了两个事件:一个打开它,然后一个再次关闭它。在我看来,几个月来工作正常。现在突然间,不同的行为......无法弄清楚为什么会这样。呜呜……
这是 HTML 部分 for this example here:
<body>
<div class="cctabs" style="height: 780px; width: 1135px;">
<div id="div_graph" style="width: 1115px; height: 650px;"></div>
<div style="text-align: right; margin-right: 50px">
<button id="updateLegend" style="">Show Legend</button><br />
<button id="showAll" style="margin-top: 5px">Show All</button> <button id="hideAll" >Hide All</button>
</div>
</div>
这是 jquery 部分:
$('#updateLegend').click(function (e)
{
var legend = chart.legend;
alert(legend.display);
if(legend.display) {
legend.group.hide();
$('#updateLegend').html('Show Legend');
legend.display = false;
} else {
legend.group.show();
$('#updateLegend').html('Hide Legend');
legend.display = true;
}
});
当点击 "Show Legend" 时,它首先提醒我图例已关闭,然后将其打开。正确的行为。但突然它再次运行脚本,将其关闭。这是为什么?
感谢任何提示!
click() event is calling twice in jquery
检查这个 SO 答案。
试试这些:
Make sure and check that you have not accidentally included your script twice in your HTML page.
或
Make unbind before the click;
$("#updateLegend").unbind('click');
$("#updateLegend")
.button()
.click(function () {
// Functionality;
});
我有一个问题,点击一个按钮来显示 Highcharts 图的图例似乎触发了两个事件:一个打开它,然后一个再次关闭它。在我看来,几个月来工作正常。现在突然间,不同的行为......无法弄清楚为什么会这样。呜呜……
这是 HTML 部分 for this example here:
<body>
<div class="cctabs" style="height: 780px; width: 1135px;">
<div id="div_graph" style="width: 1115px; height: 650px;"></div>
<div style="text-align: right; margin-right: 50px">
<button id="updateLegend" style="">Show Legend</button><br />
<button id="showAll" style="margin-top: 5px">Show All</button> <button id="hideAll" >Hide All</button>
</div>
</div>
这是 jquery 部分:
$('#updateLegend').click(function (e)
{
var legend = chart.legend;
alert(legend.display);
if(legend.display) {
legend.group.hide();
$('#updateLegend').html('Show Legend');
legend.display = false;
} else {
legend.group.show();
$('#updateLegend').html('Hide Legend');
legend.display = true;
}
});
当点击 "Show Legend" 时,它首先提醒我图例已关闭,然后将其打开。正确的行为。但突然它再次运行脚本,将其关闭。这是为什么?
感谢任何提示!
click() event is calling twice in jquery
检查这个 SO 答案。
试试这些:
Make sure and check that you have not accidentally included your script twice in your HTML page.
或
Make unbind before the click;
$("#updateLegend").unbind('click');
$("#updateLegend")
.button()
.click(function () {
// Functionality;
});