【问题标题】:ASP.net Jquery cant find prettyPhoto() functionASP.net Jquery 找不到 prettyPhoto() 函数
【发布时间】:2012-02-17 07:08:51
【问题描述】:

我一直坚持这一点,所以我想我会问其他更聪明的人:) 我有一个 .NET 网站,我正在尝试使用 prettyPhoto Jquery 插件。我已经包含了 Jquery 主库和 PrettyPhoto .js 文件在母版页中。我在使用其他 Jquery 插件时也遇到了类似的问题,我无法在库中找到该函数,避免这些问题的最佳方法是什么?我应该将所有 Jquery 文件保留在母版页中,对吗?还有 CSS 链接?我已经在我的页面上发布了代码,请通过代码举例说明如何获取 prettyPhoto() 函数。提前致谢!!

  <%@ Page Title="" Language="C#" MasterPageFile="~/Project.Master"    
  AutoEventWireup="true" CodeBehind="Portfolio.aspx.cs" Inherits="Project.Portfolio" %>
  <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

 <script type="text/javascript" charset="utf-8">
    $(document).ready(function () {
     debugger;
       //This throws error Object doesn't support property or method 'prettyPhoto'
       $("ul.gallery").prettyPhoto();
     });
</script>
  <link rel="stylesheet" href="../Stylesheets/prettyPhoto.css" type="text/css"     
  media="screen" title="prettyPhoto main stylesheet" charset="utf-8" />
  <style type="text/css" media="screen">

  ul li { display: inline; }

  </style>

  </asp:Content>
 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

 <div id="main">
 <h2>Gallery</h2>
        <ul id="picGallery" class="gallery">
            <li><a href="../images/Portfolio/fullscreen/2krew.jpg"    
 rel="prettyPhoto[gallery1]" title="You can add caption to pictures. You can add    
 caption to pictures. You can add caption to pictures."><img src="../images/thumbnails
 /2Krewtn.jpg" width="200" height="200" alt="Red round shape" /></a></li>
            <li><a href="../images/Portfolio/fullscreen/anaura" 
 rel="prettyPhoto[gallery1]" title="You can add caption to pictures. You can add 
 caption to pictures. You can add caption to pictures."><img src="../images/thumbnails
 /anauratn.jpg" width="200" height="200" alt="Red round shape" /></a></li>
            <li><a href="../images/Portfolio/fullscreen/closed.jpg" 
 rel="prettyPhoto[gallery1]" title="You can add caption to pictures. You can add 
 caption to pictures. You can add caption to pictures."><img src="../images/thumbnails
 /Closedtn.jpg" width="200" height="200" alt="Red round shape" /></a></li>

        </ul>

 </div>

 </asp:Content>

【问题讨论】:

  • 我会从Firebug 开始,看看您是否遇到任何可能阻止您的脚本正常运行的异常(以及是否实际加载了您的脚本文件)

标签: jquery asp.net asp.net-mvc-3 jquery-ui jquery-plugins


【解决方案1】:

我不确定这是否是正确的方法,但要解决这个问题,使用 jquery 和母版页使用标准 javascript 代码而不是 jQuery document.ready 触发 jquery 插件:

我在页面底部添加了这段代码

<script type="text/javascript">
    StartJqeryPlugin();

    function StartJqeryPlugin() {

        window.setTimeout(function () {
        $("ul.gallery").prettyPhoto();
        });
        }, 250);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-05
    • 2012-12-01
    • 2018-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多