Javascript 函数未触发且控制台未提供任何见解

标签 javascript jquery

有谁知道这段JS代码有什么问题吗?该函数不会触发,控制台也不会提供任何见解。这在点击功能中可以正常工作,只需进行一些细微的更改,但在其自己的功能中却不起作用。

    //History Chart
    $expanded = true;
    var $parent;

    function graphShowHide(parent) {
        $parent = parent;
        if ($expanded) {
            $('#ExpandedGraphRow').hide("fast", function() {
            });
            if($('body').innerWidth() < 673) {
                $('div.nbs-flexisel-nav-left, div.nbs-flexisel-nav-right').css('top', '415px');
                $(parent).find('#ExpandedGraphRow').css({
                    position: 'relative',
                    bottom: '0'
                });
                $(parent).find('.animation-wrapper').animate({
                    height: '397px'},
                    200, function() {
                });
            }
            setTimeout(function($) {
                $(parent).find('.history-bar-wrapper').width('100%');
            }, 200);
            $(parent).find('h4 img').hide('fast');
            $(parent).find('h4 span').width('100%').css('float', 'none');
            $expanded = false;
            $(this).text('show history');
        } else {
            var currentWidth = $(parent).find('h4').width();
            var nthChild = $(parent).index();
            if($('body').innerWidth() > 982 && nthChild == 2) {
                $('.nbs-flexisel-nav-right').trigger('click');
            } else if($('body').innerWidth() < 983 && nthChild == 1) {
                $('.nbs-flexisel-nav-right').trigger('click');
            }
            $(parent).find('h4 span, .history-bar-wrapper').width(currentWidth);
            $(parent).find('h4 span').css('float', 'left');
            $(parent).find('h4 img').show('slow');
            $('#ExpandedGraphRow').show("slow", function() {
            });
            if($('body').innerWidth() < 673) {
                $('div.nbs-flexisel-nav-left, div.nbs-flexisel-nav-right').css('top', '748px');
                $(parent).find('#ExpandedGraphRow').css({
                    position: 'absolute',
                    bottom: '66px'
                });
                $(parent).find('.animation-wrapper').animate({
                    height: '729px'},
                    200, function() {
                    
                });
            }
            $(this).text('hide history');
            $expanded = true;
        }
    }

    $('.history-button').click(graphShowHide('.BMI'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

最佳答案

试试这个:

$('.history-button').click(function() {
    graphShowHide('.BMI');
});

关于Javascript 函数未触发且控制台未提供任何见解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27151241/

相关文章:

javascript - 理解数组的关键代码

javascript - quill js 嵌入 + 操作

javascript - 带有提交按钮的 JS 下拉菜单

jQuery:removeClass 中的通配符类选择器

javascript - $ ("Iframe").contents() 适用于本地主机但不能在线使用?

javascript - 单击事件不适用于动态添加的按钮

javascript - 个人资料图片未跨组件更新 Angular 5

javascript - 如何使用javascript变量显示图像

javascript - 使div适合剩余高度

javascript - 跨域上传图片