我使用 Highcharts 在单击背景时触发事件:
$("#my-chart").highcharts({
chart: {
type: "pie",
events: {
click: function() {
console.log("I'm working!"); // This is the event I want to trigger
};
}
}
});
var myChart = $("#my-chart").highcharts();
我想在单击图表之外的内容时触发此事件。例如:
<button>Trigger the Highcharts Event!</button>
<script>
$("button").on('click', function() {
// I'd like to trigger the event here
// $('#my-chart').click(); does nothing
// myChart.chart.events.click(); does nothing
// myChart.events.click(); does nothing
// $('#my-chart').find('rect.highcharts-background').click() does nothing
});
</script>
如何以编程方式触发事件?
<小时/>我尝试了多种方法来获取更多信息。查看arguments.callee.caller.name
,该值为""
(空字符串)。
arguments.callee.caller
给我以下内容:
function (a){a=m.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(m._data(this,"events")||{})[a.type]||[],k=m.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=m.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,g=0;while((e=f.handlers[g++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(e.namespace))&&(a.handleObj=e,a.data=e.data,c=((m.event.special[e.origType]||{}).handle||e.handler).apply(f.elem,i),void 0!==c&&(a.result=c)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}}
没有人有时间破译它!
更有用的信息是event.target
,即rect.highcharts-background
。触发点击不会执行任何操作。绝对没有。我还进行了一些其他尝试,所有这些都在上面的 $('button').click()
函数的注释中。
最佳答案
您可以添加 fireEvent
函数,然后从外部触发
此函数。
关于javascript - Highcharts触发后台点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29145461/