未捕获的TypeError ...没有方法'on'

时间:2013-10-25 16:06:46

标签: jquery uncaught-exception

Chrome开发者控制台正在给我这个,因此(我认为是因为这个)左右和子弹没有出现在我的切片盒滑块上。我只引用了jQuery一次,这似乎是另一个问题的问题,所以不确定问题是什么。

我的整个头条代码在这里:

<head>
<link rel="icon" href="favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
<meta name="robots" content="index,follow" />
<meta name="Keywords" content="Website designers Lancaster, Web developers Lancashire, Mobile Web Designers lancashire, Website Designers Morecambe, make my site mobile friendly, mobile websites, " />
<meta name="author" content="magnetikmedia web and mobile web design" />
<link rel="stylesheet" type="text/css" href="/magnetik.css" media="screen" />
<link rel="stylesheet" type="text/css" href="css/slicebox.css" />
<link rel="stylesheet" type="text/css" href="css/custom.css" />
<link rel="icon" href="favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-32427484-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') +  '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>
<script type="text/javascript"    src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>

<script type="text/javascript" src="/imageswapaudio.js">

/***********************************************
* Image Swap and HTML5 audio effect (c) Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

</script>

<script type="text/javascript">
if (screen.width<800) {
window.location="http://www.magnetikmedia.co.uk/m/index.html";
}
</script>

<script type="text/javascript" src="js/modernizr.custom.46884.js"></script>
<script type="text/javascript" src="js/jquery.slicebox.js"></script>
<script type="text/javascript">
        $(function() {

            var Page = (function() {

                var $navArrows = $( '#nav-arrows' ).hide(),
                    $navOptions = $( '#nav-options' ).hide(),
                    $shadow = $( '#shadow' ).hide(),
                    slicebox = $( '#sb-slider' ).slicebox( {
                        onReady : function() {

                            $navArrows.show();
                            $navOptions.show();
                            $shadow.show();

                        },
                        orientation : 'h',
                        cuboidsCount : 3
                    } ),

                    init = function() {

                        initEvents();

                    },
                    initEvents = function() {

                        // add navigation events
                        $navArrows.children( ':first' ).on(  'click', function() {

                            slicebox.next();
                            return false;

                        } );

                        $navArrows.children( ':last' ).on( 'click', function() {

                            slicebox.previous();
                            return false;

                        } );

                        $( '#navPlay' ).on( 'click',  function() {

                            slicebox.play();
                            return false;

                        } );

                        $( '#navPause' ).on( 'click', function() {

                            slicebox.pause();
                            return false;

                        } );

                    };

                    return { init : init };

            })();

            Page.init();

        });
    </script>

</head>

2 个答案:

答案 0 :(得分:3)

2件事:

on() was added only in version 1.7,因此您必须更新正在使用的jquery版本。

升级库后,只需将引用移至google跟踪代码上方的jquery即可。

<script type="text/javascript"    src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<script type="text/javascript">

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-32427484-1']);
    _gaq.push(['_trackPageview']);

    (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') +  '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

    })();

</script>

现在,如果由于某种原因你无法升级到1.7或更高版本,你可以使用live() instead of on()

答案 1 :(得分:1)

由于jQuery,你有这个错误。你已经包含jQuery版本1.6和.on()方法包含在jQuery 1.7中,所以请包含jQuery 1.7.2(标准版)来解决你的问题..

Jquery on()