繁体   English   中英

jQuery在页面刷新时未定义

[英]jQuery is undefined on page refresh

我认为这个问题在其他任何地方都没有提出,但是如果我错了,请纠正我。

我使用的是在网上找到的漂亮的javascript代码,用于在页面上添加图片幻灯片。 我已将其添加到ASP.NET页,并且工作正常,图像以适当的间隔正确显示。 但是,问题在于,每当刷新页面时(顺便说一句,我刷新页面(F5或地址栏上的“刷新”按钮,我正在IE9上进行测试),都会出现此错误消息:行:17错误:“ jQuery”是未定义

后跟:Line:44错误:属性'jQuery'的值为null或未定义,不是Function对象。

当我转到另一页并单击“上一步”按钮时,幻灯片也可以正常运行。 看来问题仅出现在页面刷新上。

这是ASP标头内容标签中的代码:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="Scripts/fadeslideshow.js"></script>

幻灯片的代码摘自“ Dynamic Drive”(幻灯片中的终极淡入v2.0) http://www.dynamicdrive.com/

我尝试将javascript引用移动到ASP正文内容标签内的底部,以防该错误与页面加载时调用javascript的顺序有关。 虽然我真的不知道,现在有点卡住了。 任何帮助表示赞赏。

ASP.NET页面的代码:

<%@ Page Title="Community Support" Language="VB" MasterPageFile="~/Main.Master" AutoEventWireup="false"
CodeFile="Copy of CommunitySupport.aspx.vb" Inherits="CommunitySupport" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="Scripts/fadeslideshow.js">

    /***********************************************
    * Ultimate Fade In Slideshow v2.0- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for this script and 100s more
    ***********************************************/
</script>
<script type="text/javascript">

    var defaultPhoto1 = new String("");
    var defaultPhoto2 = new String("");
    var defaultCaption1 = new String("");
    var defaultCaption2 = new String("");

    defaultCaption1 = "caption A";
    defaultCaption2 = "caption B";

    defaultPhoto1 = "Images/photo1.png";
    defaultPhoto2 = "Images/photo2.png";

    function getSlideShowImages() {

                var mygallery = new fadeSlideShow({
                wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
                dimensions: [320, 220], //width/height of gallery in pixels. Should reflect dimensions of largest image
                imagearray: [
                [defaultPhoto1, "", "", defaultCaption1],
                [defaultPhoto2, "", "", defaultCaption2]

            ] //<--no trailing comma after very last image element!
            ,
                displaymode: { type: 'auto', pause: 2500, cycles: 0, wraparound: false },
                persist: false, //remember last viewed slide and recall within same session?
                fadeduration: 500, //transition duration (milliseconds)
                descreveal: "ondemand",
                togglerid: ""
            })            
    }
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:HiddenField ID="hidSlideShow" runat="server"/>            
<asp:HiddenField ID="hidCaptions" runat="server"/>
<table width="100%">
    <tr>
        <td width="60%" valign="top">
                    <table width="100%">
                        <tr>
                            <td width="100%" valign="bottom" class="heading1">Title
                            </td>                                                            
                        </tr>                              
                        <tr>
                            <td width="100%"><br />Content
                            </td>
                        </tr>
                        <tr>                                
                        </tr>
                    </table>
        </td>
        <td width="40%" valign="top">
            <div id="fadeshow1" class="slideDiv">
            </div>
        </td>
    </tr>
</table>

“ fadeshow1” div是显示幻灯片的位置。

jQuery ver中有一个错字。 1.4.2库脚本参考。 您需要在ASP标头内容设置中正确引用jQuery库,

src="http://ajax.googleapis.com/ajax/libs/jquery/1.42./jquery.min.js"

至:

src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"

我还注意到,每次初始化fadeSlideShow对象时,您都会丢失终止分号:

var mygallery = new fadeSlideShow({
            wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
            dimensions: [320, 220], //width/height of gallery in pixels. Should reflect dimensions of largest image
            imagearray: [
            [imageArray[0], imageArray[0], "_new", captionArray[0]],
            [imageArray[1], imageArray[1], "_new", captionArray[1]],
            [imageArray[2], imageArray[2], "_new", captionArray[2]],
            [imageArray[3], imageArray[3], "_new", captionArray[3]]

        ] //<--no trailing comma after very last image element!
        ,
            displaymode: { type: 'auto', pause: 2500, cycles: 0, wraparound: false },
            persist: false, //remember last viewed slide and recall within same session?
            fadeduration: 500, //transition duration (milliseconds)
            descreveal: "ondemand",
            togglerid: ""
        }); //<-- semi-colon here

进行更改后,请不要忘记清除浏览器缓存。

看起来您需要将函数放入“就绪”函数中。 http://api.jquery.com/ready/

$(document).ready(function() {
  getSlideShowImages();
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM