我一直坚持这一点,所以我想问别人更聪明:)我有一个.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>
答案 0 :(得分:0)
我不确定这是否是正确的方法,但是要解决这个问题,jquery和master页面使用标准的javascript代码触发jquery插件,而不是jQuery document.ready:
在我的页面底部,我添加了此代码
<script type="text/javascript">
StartJqeryPlugin();
function StartJqeryPlugin() {
window.setTimeout(function () {
$("ul.gallery").prettyPhoto();
});
}, 250);
}