简体   繁体   English

似乎无法弄清楚如何 get.toggle function 在 jQuery 中工作,包括该库,我有一个用于测试的 jsFiddle

[英]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.

相关问题 我的javascript函数似乎无法正常工作。 我不知道为什么 - My javascript function doesn't seem to be working. I can't figure out why 我似乎无法弄清楚如何操纵浏览器历史记录 - I can't seem to figure out how to manipulate the browser history jQuery 单击切换事件,不知道如何在 div 上进行第一次单击,然后在除 div 之外的任何位置进行第二次单击? - jQuery click toggle event, can't figure out how to have the first click on the div and second click anywhere EXCEPT the div? 似乎无法弄清楚该脚本为何不起作用 - Can't seem to figure out why the script isn't working 似乎无法弄清楚为什么我的矩阵乘法函数不起作用 - Can not seem to figure out why my matrix multiplication function is not working 似乎无法让此jsfiddle在本地工作...? - Can't seem to get this jsfiddle to work locally…? 似乎无法弄清楚为什么使用jquery单击按钮后我没有收到警报 - Can't seem to figure out why am I not getting an alert after clicking a button using jquery 我不知道我的 JavaScript 函数不起作用 - I can't figure out my JavaScript function is not working 我有一个 function 组件,不知道如何导入路由器,reactjs - I have a function component and can't figure out how to import into a router, reactjs 我似乎无法弄清楚正则表达式 - I can't seem to figure out the regular expression
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM