所以这段代码应该工作......如果我使用文本编辑器和纯 html 文档,完全相同的工作。也许我需要在视觉工作室中配置一些东西?
我正在尝试每五秒旋转以下四个图像。这是 JScript1.js 文件:
var imageArray = ["http://localhost:53734/Content/themes/base/images/oly1.jpg", "http://localhost:53734/Content/themes/base/images/oly2.jpg", "http://localhost:53734/Content/themes/base/images/oly3.jpg", "http://localhost:53734/Content/themes/base/images/oly4.jpg"];
var imageIndex = 0;
var myImage = document.getElementById("rotatingBanner");
function changeImage() {
myImage.setAttribute("src", imageArray[imageIndex]);
imageIndex++;
if (imageIndex >= imageArray.length) {
imageIndex = 0;
}
}
var intervalHandle = setInterval(changeImage, 5000);
这是它运行的视图:
@{
ViewBag.Title = "Home Page";
}
<h2>@ViewBag.Message</h2>
<h4>View results by:</h4>
<ul id="friend">
<li>@Html.ActionLink("Countries", "Countries", "Home")</li>
<li>@Html.ActionLink("Events", "Events", "Home")</li>
</ul>
<div>
<img id="rotatingBanner" src="http://localhost:53734/Content/themes/base/images/oly1.jpg" />
</div>
<script src="http://localhost:53734/Scripts/JScript1.js"/>
我们在视图中请求的图像出现了,但 5 秒后它没有像应有的那样旋转。