[英]Can't seem to figure out how to get .toggle function working in jQuery, the library is included, I have a jsFiddle for testing
I can't seem to figure out why none of my console logs or alerts are working in this jQuery toggle function.我似乎无法弄清楚为什么我的控制台日志或警报都没有在这个 jQuery 切换 function 中工作。 I haven't used jQuery in a while so am not sure If I am doing something wrong or if there is a configuration issue with the script include.
我已经有一段时间没有使用 jQuery 了,所以不确定我是否做错了什么,或者脚本是否存在配置问题。
Here is the js fiddle https://jsfiddle.net/anders_kitson/8ar9mvp4/1/这是js小提琴https://jsfiddle.net/anders_kitson/8ar9mvp4/1/
Here is the code这是代码
var chart = Highcharts.chart('container', {
credits: {
enabled: false
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}],
navigation: {
buttonOptions: {
enabled: false
}
}
});
const b = document.createElement('button');
b.textContent = ' ';
b.style.position = 'absolute';
b.style.right = "0px"
b.style.top = '10px';
b.className = "toggleMe"
b.setAttribute("id", "buttonToggle");
$( "#buttonToggle" ).toggle(function() {
alert( "First handler for .toggle() called." );
console.log("test")
}, function() {
alert( "Second handler for .toggle() called." );
console.log("test1")
});
/* b.addEventListener('click', function () {
chart.fullscreen.toggle();
//b.classList.remove("toggleMe");
//b.className = "toggleMeOff"
}); */
chart.container.appendChild(b);
I don't know which function you would like to expect with the toggle.我不知道您希望切换哪个 function 。
This code gives you the second handler alert.此代码为您提供第二个处理程序警报。
$( "#container" ).after('<button id="buttonToggle">Click Me!</button>');
$( "#buttonToggle" ).toggle(function() {
alert( "First handler for .toggle() called." );
console.log("test")
}, function() {
alert( "Second handler for .toggle() called." );
console.log("test1")
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.