旋转图像javascript - 图像不旋转 - MVC3

时间:2012-08-23 17:09:59

标签: javascript html asp.net-mvc-3

所以这段代码应该工作......如果我使用文本编辑器和普通的html文档,完全相同的东西。也许我需要在visual studio中配置一些东西?

我试图每五秒旋转以下四张图像。这是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秒后旋转。

1 个答案:

答案 0 :(得分:0)

我没有恰当地关闭脚本标记: 应该用

关闭
</script>

不是

script.js/>