TypeError:$(...)不是函数错误

时间:2014-07-09 07:40:12

标签: javascript jquery

我已经检查了旧线程,但我仍然无法解决它。

它退出jquery认为,但我已经把jquery放在文件中。

有人可以告诉我这里的问题是什么吗?

代码是关于显示图形和按钮单击切片显示其他图形。

代码:

<!DOCTYPE html>
<html lang="en">
    <head>
    <script src="http://code.highcharts.com/highcharts.js"></script>
        <script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script src="http://code.highcharts.com/modules/exporting.js"></script>
        <script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script>

</head>
    <body>

    <div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>

    </body>
        <script>
    $(function () {
            $('#container').highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: 1,//null,
                plotShadow: false
            },
            title: {
                text: 'Browser market shares at a specific website, 2014'
            },
            tooltip: {

                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            },
            plotOptions: {
                pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'

                    }
                }
                }
            },
            series: [{
                type: 'pie',
                name: 'Browser share',

                data: [
                ['Firefox',   45.0],
                ['IE',       26.8],
                {
                name: 'Chrome',
                y: 12.8,
                sliced: true,
                    selected: true
            },
        ['Safari',    8.5],
            ['Opera',     6.2],
            ['Others',   0.7]
            ]
            }]
            });
        });       
        </script>
<html>

2 个答案:

答案 0 :(得分:3)

Highcharts依赖于jQuery。所以你必须在 highcharts之前包含jQuery

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>

答案 1 :(得分:0)

在引用高级脚本之前,您需要参考JQuery。

会有一些变化:

  1. 仅指一个JQuery

  2. $(文档).ready(function(){})中填写您的脚本;

  3. 请参阅更新后的代码:

    <html lang="en">
        <head>
    <script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script>
    <script src="http://code.highcharts.com/modules/exporting.js"></script>
    <script src="http://code.highcharts.com/highcharts.js"></script>
    
    </head>
        <body>
    
        <div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
    
        </body>
            <script>
    $(document).ready(function(){
        $(function () {
                $('#container').highcharts({
                chart: {
                    plotBackgroundColor: null,
                    plotBorderWidth: 1,//null,
                    plotShadow: false
                },
                title: {
                    text: 'Browser market shares at a specific website, 2014'
                },
                tooltip: {
    
                    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                },
                plotOptions: {
                    pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                        style: {
                            color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
    
                        }
                    }
                    }
                },
                series: [{
                    type: 'pie',
                    name: 'Browser share',
    
                    data: [
                    ['Firefox',   45.0],
                    ['IE',       26.8],
                    {
                    name: 'Chrome',
                    y: 12.8,
                    sliced: true,
                        selected: true
                },
            ['Safari',    8.5],
                ['Opera',     6.2],
                ['Others',   0.7]
                ]
                }]
                });
            });    
     });    
            </script>
    <html>