Jquery NivoSlider Slider无效$('#slider')。nivoSlider();不是一个功能

时间:2012-06-14 15:22:55

标签: javascript jquery asp.net slider

我在我的asp.net应用程序中使用nivo jquery图像滑块,但是在页面加载后它没有更改图像并且只显示“loading.gif”图像,在jquery调试时我收到错误消息:$('#slider “).nivoSlider();不是一个功能。

   <link href="css/NivoSlideThemes/default/default.css" rel="stylesheet" type="text/css" media="screen" />
    <link href="css/NivoSlideThemes/nivo-slider.css" rel="stylesheet" type="text/css" media="screen"  />
    <script src="js/menu/jquery-1.7.2.min.js" type="text/javascript"></script>     
    <script src="js/jquery.nivo.slider.pack.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(window).load(function () {
            $('#slider').nivoSlider();
        });
        </script>
          <style>   

            .theme-default #slider {
                margin:1px auto 0 auto;
                width:674px; /* Make sure your images are the same size */
                height:311px; /* Make sure your images are the same size */
            }
            .theme-pascal.slider-wrapper,
            .theme-orman.slider-wrapper {
               /* margin-top:150px;  */
            }

            .clear {
                clear:both;
            }

      </style> 

       <div class="slider-wrapper theme-default"> 
            <div id="slider" class="nivoSlider">
                <img src="images/cfgSliderImages/1.gif" alt="" />
                <img src="images/cfgSliderImages/2.gif" alt="" title="Solar Power" />
                <img src="images/cfgSliderImages/3.gif" alt="" data-transition="slideInLeft" />
                <img src="images/cfgSliderImages/4.gif" alt=""   title="#htmlcaption" />
            </div>
            <div id="htmlcaption" class="nivo-html-caption">
                <strong>This</strong> is an example of a <em>HTML</em> caption with <a href="#">a link</a>.
            </div>
        </div>

2 个答案:

答案 0 :(得分:10)

试试这个:

可能与jQuery存在冲突,因此请使用.noConflict()

var j = jQuery.noConflict();
j(document).ready(function () {
    j('#slider').nivoSlider();
});

答案 1 :(得分:0)

当我偶尔使用Visual Studio时,我遇到了这个问题。我没有在body中引用脚本,而是将其添加到head

<head>
    <link href="css/NivoSlideThemes/default/default.css" rel="stylesheet" type="text/css" media="screen" />
    <link href="css/NivoSlideThemes/nivo-slider.css" rel="stylesheet" type="text/css" media="screen"  />
    <script src="js/menu/jquery-1.7.2.min.js" type="text/javascript"></script>     
    <script src="js/jquery.nivo.slider.pack.js" type="text/javascript"></script>
</head>

这也是jQuery的一个问题。

但是,您需要将javascript放在文档就绪函数中:

// When the page is ready to be manipulated
$(function() {
        $(window).load(function () {
            $('#slider').nivoSlider();
        });
});