Javascript在asp.net母版页中没有做任何事情

时间:2014-09-30 07:34:27

标签: javascript jquery html css asp.net

我在向我的asp.net母版页添加照片幻灯片时遇到问题。我正在为我的一个朋友做这个项目,他的朋友需要为她的公司建立一个网站。我已经尝试了许多不同的幻灯片演示以及使用教程从头开始编写一些代码。这不是我的主要语言,因此我发现很难确切地发现错误并尝试了所有可能的解决方案但没有成功,我决定寻求帮助。

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="WingtipToys.SiteMaster" %>

<!DOCTYPE html>

<html lang="en">
<head runat="server">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />


    <asp:PlaceHolder runat="server">
        <%: Scripts.Render("~/bundles/modernizr") %>
    </asp:PlaceHolder>
    <webopt:bundlereference runat="server" path="~/Content/css" />
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <!--######################Slider Code Start###############################-->

    <title>Featured Content Slider</title>

    <link rel="stylesheet" type="text/css" href="~/FeaturedContentSlider/style.css" />

    <script type="text/javascript" src="~/FeaturedContentSlider/js/jquery-1.2.6.min.js"></script>
    <script type="text/javascript" src="~/FeaturedContentSlider/js/jquery-easing-1.3.pack.js"></script>
    <script type="text/javascript" src="~/FeaturedContentSlider/js/jquery-easing-compatibility.1.2.pack.js"></script>
    <script type="text/javascript" src="~/FeaturedContentSlider/js/coda-slider.1.1.1.pack.js"></script>

    <script type="text/javascript">

        var theInt = null;
        var $crosslink, $navthumb;
        var curclicked = 0;

        theInterval = function (cur) {
            clearInterval(theInt);

            if (typeof cur != 'undefined')
                curclicked = cur;

            $crosslink.removeClass("active-thumb");
            $navthumb.eq(curclicked).parent().addClass("active-thumb");
            $(".stripNav ul li a").eq(curclicked).trigger('click');

            theInt = setInterval(function () {
                $crosslink.removeClass("active-thumb");
                $navthumb.eq(curclicked).parent().addClass("active-thumb");
                $(".stripNav ul li a").eq(curclicked).trigger('click');
                curclicked++;
                if (6 == curclicked)
                    curclicked = 0;

            }, 3000);
        };

        $(function () {

            $("#main-photo-slider").codaSlider();

            $navthumb = $(".nav-thumb");
            $crosslink = $(".cross-link");

            $navthumb
            .click(function () {
                var $this = $(this);
                theInterval($this.parent().attr('href').slice(1) - 1);
                return false;
            });

            theInterval();
        });
    </script>
        <!--######################Slider Code End###############################-->
</head>
<body>
    <form runat="server">
        <asp:ScriptManager runat="server">
            <Scripts>
                <%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=301884 --%>
                <%--Framework Scripts--%>
                <asp:ScriptReference Name="MsAjaxBundle" />
                <asp:ScriptReference Name="jquery" />
                <asp:ScriptReference Name="bootstrap" />
                <asp:ScriptReference Name="respond" />
                <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
                <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
                <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
                <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
                <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
                <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
                <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
                <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
                <asp:ScriptReference Name="WebFormsBundle" />
                <%--Site Scripts--%>
            </Scripts>
        </asp:ScriptManager>

        <div class="navbar navbar-inverse navbar-fixed-top">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" runat="server" href="~/">Wingtip Toys</a>
                </div>
                <div class="navbar-collapse collapse">
                    <ul class="nav navbar-nav">
                        <li><a runat="server" id="adminLink" visible="false" 
                          href="~/Admin/AdminPage">Admin</a></li>
                        <li><a runat="server" href="~/">Home</a></li>
                        <li><a runat="server" href="~/About">About</a></li>
                        <li><a runat="server" href="~/Contact">Contact</a></li>
                        <li><a runat="server" href="~/ProductList">Products</a></li>
                        <li><a runat="server" href="~/ShoppingCart" ID="cartCount">&nbsp;</a></li>
                    </ul>
                    <asp:LoginView runat="server" ViewStateMode="Disabled">
                        <AnonymousTemplate>
                            <ul class="nav navbar-nav navbar-right">
                                <li><a runat="server" href="~/Account/Register">Register</a></li>
                                <li><a runat="server" href="~/Account/Login">Log in</a></li>
                            </ul>
                        </AnonymousTemplate>
                        <LoggedInTemplate>
                            <ul class="nav navbar-nav navbar-right">
                                <li><a runat="server" href="~/Account/Manage" title="Manage your account">Hello, <%: Context.User.Identity.GetUserName()  %> !</a></li>
                                <li>
                                    <asp:LoginStatus runat="server" LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/" OnLoggingOut="Unnamed_LoggingOut" />
                                </li>
                            </ul>
                        </LoggedInTemplate>
                    </asp:LoginView>
                </div>
            </div>
        </div>

        <!--######################Slider Code Start###############################-->
        <div id="page-wrap">

    <div class="slider-wrap">
        <div id="main-photo-slider" class="csw">
            <div class="panelContainer">

                <div class="panel" title="Panel 1">
                    <div class="wrapper">
                        <img src="FeaturedContentSlider/images/tempphoto-1.jpg" alt="temp" />
                        <div class="photo-meta-data">
                            Photo Credit: <a href="http://flickr.com/photos/astrolondon/2396265240/">Kaustav Bhattacharya</a><br />
                            <span>"Free Tibet" Protest at the Olympic Torch Rally</span>
                        </div>
                    </div>
                </div>
                <div class="panel" title="Panel 2">
                    <div class="wrapper">
                        <img src="FeaturedContentSlider/images/tempphoto-2.jpg" alt="temp" />
                        <div class="photo-meta-data">
                            Chicago Bears at Seattle Seahawks<br />
                            <span>Fifth field goal, overtime win for the Seahawks</span>
                        </div>
                    </div>
                </div>      
                <div class="panel" title="Panel 3">
                    <div class="wrapper">

                        <img src="FeaturedContentSlider/images/scotch-egg.jpg" alt="scotch egg" class="floatLeft"/>

                        <h1>How to Cook a Scotch Egg</h1>

                        <ul>
                            <li>6 hard-boiled eggs, well chilled</li>
                            <li>1 pound good quality sausage meat</li>
                            <li>1/2 cup AP flour</li>
                            <li>1-2 eggs, beaten</li>
                            <li>3/4 cup panko-style bread crumbs</li>
                            <li>Vegetable oil for frying</li>
                        </ul>
                    </div>
                </div>
                <div class="panel" title="Panel 4">
                    <div class="wrapper">
                        <img src="FeaturedContentSlider/images/tempphoto-4.jpg" alt="temp" />
                        <div class="photo-meta-data">
                            A Poem by Shel Silverstein<br />
                            <span>Falling Up</span>
                        </div>
                    </div>
                </div>
                <div class="panel" title="Panel 5">
                    <div class="wrapper">
                        <img src="FeaturedContentSlider/images/tempphoto-5.jpg" alt="temp" />
                        <div class="photo-meta-data">
                            New Video on CSS-Tricks<br />
                            <span>Using Wufoo for Web Forms</span>
                        </div>
                    </div>
                </div>
                <div class="panel" title="Panel 6">
                    <div class="wrapper">
                        <h1>A Tale of Two Cities</h1>
                        <p><em>Charles Dickins</em></p>
                        <blockquote>It was the best of times</blockquote>
                    </div>
                </div>

            </div>
        </div>

        <a href="#1" class="cross-link active-thumb"><img src="FeaturedContentSlider/images/tempphoto-1thumb.jpg" class="nav-thumb" alt="temp-thumb" /></a>
        <div id="movers-row">
            <div><a href="#2" class="cross-link"><img src="FeaturedContentSlider/images/tempphoto-2thumb.jpg" class="nav-thumb" alt="temp-thumb" /></a></div>
            <div><a href="#3" class="cross-link"><img src="FeaturedContentSlider/images/tempphoto-3thumb.jpg" class="nav-thumb" alt="temp-thumb" /></a></div>
            <div><a href="#4" class="cross-link"><img src="FeaturedContentSlider/images/tempphoto-4thumb.jpg" class="nav-thumb" alt="temp-thumb" /></a></div>
            <div><a href="#5" class="cross-link"><img src="FeaturedContentSlider/images/tempphoto-5thumb.jpg" class="nav-thumb" alt="temp-thumb" /></a></div>
            <div><a href="#6" class="cross-link"><img src="FeaturedContentSlider/images/tempphoto-6thumb.jpg" class="nav-thumb" alt="temp-thumb" /></a></div>
        </div>

    </div>

    </div>
        <!--######################Slider Code End###############################-->
        <div id="TitleContent" style="text-align: center">
            <a runat="server" href="~/">
                <asp:Image  ID="Image1" runat="server" ImageUrl="~/Images/logo.jpg" BorderStyle="None" />
            </a>  
            <br />  
        </div>
        <div id="CategoryMenu" style="text-align: center">       
            <asp:ListView ID="categoryList"  
                ItemType="WingtipToys.Models.Category" 
                runat="server"
                SelectMethod="GetCategories" >
                <ItemTemplate>
                    <b style="font-size: large; font-style: normal">
                    <a href="<%#: GetRouteUrl("ProductsByCategoryRoute", new {categoryName = Item.CategoryName}) %>">
                        <%#: Item.CategoryName %>
                    </a>
                    </b>
                </ItemTemplate>
                <ItemSeparatorTemplate>  |  </ItemSeparatorTemplate>
            </asp:ListView>
        </div>
        <div class="container body-content">
            <asp:ContentPlaceHolder ID="MainContent" runat="server">
            </asp:ContentPlaceHolder>
            <hr />
            <footer>
                <p>&copy; <%: DateTime.Now.Year %> - Wingtip Toys</p>
            </footer>
        </div>
    </form>
</body>
</html>

所以目前正在发生的是,Style.css文件被访问,但没有任何javascript文件似乎在做任何事情。显示滑块,但所有图像垂直放置在彼此之下,因此我有一长行图像垂直向下运行。很抱歉,如果格式化已关闭或者没有足够的细节,这是我在这里的第一篇文章,我通常会自行解决问题。谢谢你的帮助!!

编辑:

我从javascript路径中删除了tilda“〜”并且似乎找到了java文件,当我按F12或“Ctrl + shift + j”时,我收到以下错误:“未捕获的typeError:undefined不是函数“在线:”$(“#main-photo-slider”)。codaSlider();“

编辑2:

我无法上传控制台输出的屏幕截图,因为我的声誉是惊人的1分,但以下是在控制台输出中的Frames-&gt; Default-&gt; Scripts下列出的。

  

jquery-easing-compatibility.1.2.pack.js,jquery-easing-1.3.pack.js,   jquery-1.2.6.min.js,coda-slider.1.1.1.pack.js,jquery-1.10.2.js,   ycodaslider-2.0.pack.js,

这是index.html文件中的代码,当我尝试在我的site.master页面中执行相同操作时,它只是不起作用。

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
			   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

  <title>Featured Content Slider</title>

  <link rel="stylesheet" type="text/css" href="style.css" />

  <script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
  <script type="text/javascript" src="js/jquery-easing-1.3.pack.js"></script>
  <script type="text/javascript" src="js/jquery-easing-compatibility.1.2.pack.js"></script>
  <script type="text/javascript" src="js/coda-slider.1.1.1.pack.js"></script>

  <script type="text/javascript">
    var theInt = null;
    var $crosslink, $navthumb;
    var curclicked = 0;

    theInterval = function(cur) {
      clearInterval(theInt);

      if (typeof cur != 'undefined')
        curclicked = cur;

      $crosslink.removeClass("active-thumb");
      $navthumb.eq(curclicked).parent().addClass("active-thumb");
      $(".stripNav ul li a").eq(curclicked).trigger('click');

      theInt = setInterval(function() {
        $crosslink.removeClass("active-thumb");
        $navthumb.eq(curclicked).parent().addClass("active-thumb");
        $(".stripNav ul li a").eq(curclicked).trigger('click');
        curclicked++;
        if (6 == curclicked)
          curclicked = 0;

      }, 3000);
    };

    $(function() {

      $("#main-photo-slider").codaSlider();

      $navthumb = $(".nav-thumb");
      $crosslink = $(".cross-link");

      $navthumb
        .click(function() {
          var $this = $(this);
          theInterval($this.parent().attr('href').slice(1) - 1);
          return false;
        });

      theInterval();
    });
  </script>
  </head>

  <body>

  <div id="page-wrap">

    <div class="slider-wrap">
      <div id="main-photo-slider" class="csw">
        <div class="panelContainer">

          <div class="panel" title="Panel 1">
            <div class="wrapper">
              <img src="images/tempphoto-1.jpg" alt="temp" />
              <div class="photo-meta-data">
                Photo Credit: <a href="http://flickr.com/photos/astrolondon/2396265240/">Kaustav Bhattacharya</a>
                <br />
                <span>"Free Tibet" Protest at the Olympic Torch Rally</span>
              </div>
            </div>
          </div>
          <div class="panel" title="Panel 2">
            <div class="wrapper">
              <img src="images/tempphoto-2.jpg" alt="temp" />
              <div class="photo-meta-data">
                Chicago Bears at Seattle Seahawks
                <br />
                <span>Fifth field goal, overtime win for the Seahawks</span>
              </div>
            </div>
          </div>
          <div class="panel" title="Panel 3">
            <div class="wrapper">

              <img src="images/scotch-egg.jpg" alt="scotch egg" class="floatLeft" />

              <h1>How to Cook a Scotch Egg</h1>

              <ul>
                <li>6 hard-boiled eggs firm up)</li>
                <li>1 pound good quality</li>
                <li>1/2 cup AP flour</li>
                <li>1-2 eggs, beaten</li>
                <li>3/4 cup panko-style bread crumbs</li>
                <li>Vegetable oil for frying</li>
              </ul>
            </div>
          </div>
          <div class="panel" title="Panel 4">
            <div class="wrapper">
              <img src="images/tempphoto-4.jpg" alt="temp" />
              <div class="photo-meta-data">
                A Poem by Shel Silverstein
                <br />
                <span>Falling Up</span>
              </div>
            </div>
          </div>
          <div class="panel" title="Panel 5">
            <div class="wrapper">
              <img src="images/tempphoto-5.jpg" alt="temp" />
              <div class="photo-meta-data">
                New Video on CSS-Tricks
                <br />
                <span>Using Wufoo for Web Forms</span>
              </div>
            </div>
          </div>
          <div class="panel" title="Panel 6">
            <div class="wrapper">
              <h1>A Tale of Two Cities</h1>
              <p><em>Charles Dickins</em>
              </p>
              <blockquote>It was the best of times, en, we were all going direct</blockquote>
            </div>
          </div>

        </div>
      </div>

      <a href="#1" class="cross-link active-thumb">
        <img src="images/tempphoto-1thumb.jpg" class="nav-thumb" alt="temp-thumb" />
      </a>
      <div id="movers-row">
        <div>
          <a href="#2" class="cross-link">
            <img src="images/tempphoto-2thumb.jpg" class="nav-thumb" alt="temp-thumb" />
          </a>
        </div>
        <div>
          <a href="#3" class="cross-link">
            <img src="images/tempphoto-3thumb.jpg" class="nav-thumb" alt="temp-thumb" />
          </a>
        </div>
        <div>
          <a href="#4" class="cross-link">
            <img src="images/tempphoto-4thumb.jpg" class="nav-thumb" alt="temp-thumb" />
          </a>
        </div>
        <div>
          <a href="#5" class="cross-link">
            <img src="images/tempphoto-5thumb.jpg" class="nav-thumb" alt="temp-thumb" />
          </a>
        </div>
        <div>
          <a href="#6" class="cross-link">
            <img src="images/tempphoto-6thumb.jpg" class="nav-thumb" alt="temp-thumb" />
          </a>
        </div>
      </div>

    </div>

  </div>

  </body>

  </html>

以下是我尝试使用的滑块的链接:http://css-tricks.com/creating-a-slick-auto-playing-featured-content-slider/随滑块一起提供的index.html。但是我无法在我的site.master中使用相同的功能。

2 个答案:

答案 0 :(得分:0)

尝试使用不带&#34; &#34;的脚本源。以&#34; / &#34;开头足以在HTML中达到root。 &#34;的&#34;在服务器端可用。

答案 1 :(得分:0)

假设您的图像已显示,尽管不在Slider中,您应该查看浏览器开发工具[F12]以验证:

  • 加载所有页面资源,即状态代码全部为200
  • 在控制台中查找JavaScript错误

在整个JavaScript中编写一些console.log和console.debug语句,以帮助分析不符合预期的事项。

确保JavaScript中引用的所有css选择器都映射到某些内容,例如

.stripNav ul li a