我认为这个问题在其他任何地方都没有提出,但如果我错了,请纠正我。
我正在使用我在网上找到的一段漂亮的javascript代码,用于在页面上添加图片幻灯片。我已将它添加到ASP.NET页面,它工作正常,图像以适当的间隔正确显示。但是,问题在于每当我刷新页面时(地址栏上的F5或“刷新”按钮,顺便说一下我在IE9上进行测试),会出现以下错误消息: 行:17 错误:'jQuery'未定义
其次是: 行: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>
幻灯片的代码取自“动态驱动器”(Ultimate Fade In Slideshow 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是幻灯片显示的位置。
答案 0 :(得分:0)
你的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
进行更改后,请不要忘记清除浏览器缓存。
答案 1 :(得分:0)
看起来你需要将函数放在“就绪”函数中。 http://api.jquery.com/ready/
$(document).ready(function() {
getSlideShowImages();
});