【问题标题】:MVC4 + jQuery fade out notification divMVC4 + jQuery 淡出通知 div
【发布时间】:2014-02-12 11:35:59
【问题描述】:

我对使用 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>

【问题讨论】:

    标签: c# javascript jquery asp.net-mvc-4


    【解决方案1】:

    你需要在id选择器之前使用#

    <script>
        $("#Notification").fadeOut(1000);
        //.^...........
    </script>
    

    http://api.jquery.com/id-selector/

    【讨论】:

    • 谢谢,真不敢相信我错过了那个。
    猜你喜欢
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多