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

标签 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);

这是它运行的 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/

相关文章:

asp.net-mvc-3 - ASP.NET 成员(member)资格 - 登录在本地有效,但在 Azure 上失败

asp.net-mvc - 如何选择下拉列表值并在mvc3中显示?

asp.net-mvc - 带有 GET 方法的 Html.BeginForm()

javascript - 即使在添加 CORS 配置后,S3 也会出现 CORS 错误

javascript - 如何解决Sencha Touch中clear Filter()函数的性能问题?

javascript - 将文本区域的内容保存到文件并从 PHP 服务器页面加载

html - 如何更改 iconfont 图标的悬停颜色?

javascript - jQuery thead 对象不能 append tr 对象

javascript - 来自 app.component.ts 的 Angular 路由

php - 将链接重定向到同一页面