ASP.net Jquery 找不到 PrettyPhoto() 函数

发布于 2025-01-06 16:34:59 字数 2355 浏览 0 评论 0原文

我在这个问题上停留了一段时间,所以想我应该问其他更聪明的人:)我有一个 .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>

Iv been stuck on this for a little bit so figured i would ask someone else smarter :) I have a .NET website that I am trying to use the prettyPhoto Jquery plug in. I have included the Jquery main library and the PrettyPhoto.js file in the master page. I have been having similar problems with other Jquery plugins too where I cant find the function in the library, Whats the best way to avoid these problems? I am supposed to keep all the Jquery files in the master page right? and the CSS links as well? I have posted the code on my page, please give an example by code how to get the prettyPhoto() function. Thanks in advance!!

  <%@ 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神回复 2025-01-13 16:34:59

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

在我的页面底部我添加了此代码

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

    function StartJqeryPlugin() {

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

I'm not sure if this is the correct approach, but to solve this issue with jquery and master pages firing the jquery plug in with standart javascript code, rather then the jQuery document.ready:

On the bottom of my page I added this code

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

    function StartJqeryPlugin() {

        window.setTimeout(function () {
        $("ul.gallery").prettyPhoto();
        });
        }, 250);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文