[英]MVC4 + jQuery fade out notification div
我真的是JavaScript和JQuery的新手,我需要一些帮助来解决我遇到的一个简单问题。
我将根据保存到数据库的结果动态加载下面的div,并希望用户通知在一两秒钟后消失。 我编写的脚本可以正常运行,但不会使div消失。
您能让我知道我在想什么,或者是否有更好的方法可以做到这一点?
调节器
public ActionResult Index(IList<Datapoint> model)
{
if (ModelState.IsValid)
{
try
{
ctx.SaveChanges(model);
ViewBag.Notification = "Save Successful";
}
catch (Exception ex)
{
ViewBag.Notification = "Save Failed";
}
}
return View(model);
}
HTML
@if(!ViewBag.Notification.ToString().Equals(string.Empty))
{
<div id="Notification" class="large-4 large-offset-6 columns">
<h5 class="button [secondary success alert] round">@ViewBag.Notification.ToString()</h5>
</div>
}
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script>
$("Notification").fadeOut(1000);
</script>
您需要在ID选择器之前使用#
<script>
$("#Notification").fadeOut(1000);
//.^...........
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.