所以这段代码应该可以工作...如果我使用文本编辑器和纯 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);
这是它运行的 View :
@{
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"/>
我们在 View 中请求的图像显示了,但它在 5 秒后没有像应有的那样旋转。
最佳答案
我没有适本地关闭脚本标签: 它应该用
关闭</script>
不是
script.js/>
关于javascript - 旋转图像 javascript--图像不旋转--MVC3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12096812/