Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何设置jQuery以在锚定单击时启动_Jquery_Jquery Plugins - Fatal编程技术网

如何设置jQuery以在锚定单击时启动

如何设置jQuery以在锚定单击时启动,jquery,jquery-plugins,Jquery,Jquery Plugins,我一直在与Prettytoto合作建立一个简单的画廊。我的问题是,我不理解如何从开发人员手册上提供的文档中实现API。当我添加我理解的代码并单击锚时,什么都没有发生 我有一个站点。母版页和一个使用插件的内容页。以下是我在内容页中的代码: <asp:Content ID="HeadContent" runat="server" ContentPlaceHolderID="HeadContent"> <title>Gallery</title> &

我一直在与Prettytoto合作建立一个简单的画廊。我的问题是,我不理解如何从开发人员手册上提供的文档中实现API。当我添加我理解的代码并单击锚时,什么都没有发生

我有一个站点。母版页和一个使用插件的内容页。以下是我在内容页中的代码:

<asp:Content ID="HeadContent" runat="server" ContentPlaceHolderID="HeadContent">
    <title>Gallery</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />       
    <script type="text/javascript">
        $('#prettyPhoto').click(function () {
            api_images = ['images/prettyPhoto/dogs.png', 'images/prettyPhoto/Yard1.png', 'images/prettyPhoto/Yard2.png', 'images/prettyPhoto/Yard3.png'];
            api_titles = ['Title Dogs', 'Title Yard 1', 'Title Yard 2', 'Title Yard 3'];
            api_descriptions = ['Dogs', 'Yard 1', 'Yard 2', 'Yard 3'];
            $.prettyPhoto.open(api_images, api_titles, api_descriptions);
        });
    </script>
</asp:Content>

...

<a href="#" id="prettyPhoto"><img src='images/prettyPhoto/dogs.png' alt='Dogs' style="float:right; margin:0px 0px 10px 10px" /></a>

这是网站。主内容:

<head id="Head1" runat="server">
    <link rel="stylesheet" href="Styles/styles.css" type="text/css" />
    <link rel="stylesheet" href="styles/prettyPhoto.css" type="text/css" media="screen" charset="utf-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
    <script type="text/javascript" src="Scripts/jquery.cycle.all.latest.js"></script>  
    <script type="text/javascript" src="Scripts/jquery.prettyPhoto.js" charset="utf-8"></script>      
    <script type="text/javascript">
        $(document).ready(function () {
            $('.newWindow').click(function (event) {
                var url = $(this).attr("href");
                var windowName = $(this).attr("name");
                var windowSize = windowSizeArray[$(this).attr("rel")];
                window.open(url, windowName, windowSize);
                event.preventDefault();
            });            
            $('.slideshow').cycle();            
            if ($("#content").height() > $("#sidebar").height()) {
                $("#sidebar").height($("#content").height());
            }
            else {
                $("#content").height($("#sidebar").height());
            }
        });
    </script>
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
</head>

$(文档).ready(函数(){
$('.newWindow')。单击(函数(事件){
var url=$(this.attr(“href”);
var windowName=$(this.attr(“name”);
var windowSize=windowsizerray[$(this.attr(“rel”)];
打开(url、windowName、WindowsSize);
event.preventDefault();
});            
$('.slideshow').cycle();
如果($(“#内容”).height()>$(“#边栏”).height()){
$(“#边栏”).height($(“#内容”).height());
}
否则{
$(“#内容”).height($(“#边栏”).height());
}
});

我希望我没有在这里发布太多信息,但我不清楚我的错误在哪里。我知道我犯了一个错误,因为今晚早些时候,我让这个控件按照我想要的方式工作,但后来我不得不开始“微调”。在我知道之前,我已经忘记了我所做的更改并将其破坏。

好的,我发现了错误,我会发布答案,以防其他人使用它。我发现开发人员网站上的文档没有解释实现API的一些细节,但也许这些细节对于具有更多jQuery经验的人来说是显而易见的。我犯了两个错误。首先,单击处理程序需要位于$(document).ready函数的内部。其次,需要在单击处理程序中声明API调用之前调用插件。这是我真正困惑的部分;我本以为API否定了调用插件的必要性,但我的jQuery经验还是有限的。以下是最终代码:

<script type="text/javascript" src="Scripts/jquery.prettyPhoto.js" charset="utf-8"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $().prettyPhoto();
        $('#prettyPhoto').click(function () {
            api_images = ['images/prettyPhoto/dogs.png', 'images/prettyPhoto/Yard1.png', 'images/prettyPhoto/Yard2.png', 'images/prettyPhoto/Yard3.png'];
            api_titles = ['Title Dogs', 'Title Yard 1', 'Title Yard 2', 'Title Yard 3'];
            api_descriptions = ['Dogs', 'Yard 1', 'Yard 2', 'Yard 3'];
            $.prettyPhoto.open(api_images, api_titles, api_descriptions);
        });
    });
</script>

$(文档).ready(函数(){
$().pretto();
$('#to')。单击(函数(){
api_images=['images/prettypto/dogs.png'、'images/prettypto/Yard1.png'、'images/prettypto/Yard2.png'、'images/prettypto/Yard3.png';
api_标题=[‘标题狗’、‘标题码1’、‘标题码2’、‘标题码3’];
api_描述=[‘狗’、‘1号码’、‘2号码’、‘3号码’];
$.prettypto.open(api_图像、api_标题、api_描述);
});
});

通过这样做,我了解到上面的代码可以放在Site.Master或内容文件中,而且显然可以放在这些文件中的任何地方。解决这个问题还帮助我完成了我的另一个想法,即从外部XML文件动态生成整个代码块。

请随时将您的解决方案标记为已接受的答案,以方便将来的访问者。感谢您提供的精彩提示;救了我一天