开发者

How do you add jquery animation to mvc 2 rendered controls?

开发者 https://www.devze.com 2023-02-13 13:29 出处:网络
have an editor template that can be rendered 0 to n times on a given page: <%@ Control Language=\"C#\" Inherits=\"System.Web.Mvc.ViewUserControl<NewEmployee.Models.RequestedAccessViewModel>\

have an editor template that can be rendered 0 to n times on a given page:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NewEmployee.Models.RequestedAccessViewModel>" %>
<fieldset style="display: inline;">
    <legend>
        <%: Model.Description %></legend>
    <div class="editor-label">
        <%: Html.LabelFor(model => model.Requested) %>
        <%: Html.CheckBoxFor(model => model.Requested)%>
    </div>
    <div class="editor-field">
        <%: Html.TextAreaFor(model => model.Comments) %>
    </div>
    <%: Html.HiddenFor(model => model.Description) %>
    <%: Html.HiddenFor(model => model.Id) %>
</fieldset>

What I'd really like is the 'Comments' text area to 开发者_如何学运维be hidden initially, and slide down into view when the check box is hit, and slide back out if the checkbox is turned off again.

I know how I would do this with traditinal asp.net, but am at a loss with MVC2.


Use a jQuery function like this


$(document).ready(function () {

    $("div.editor-field").hide();

    $("input:checkbox").click(function () {

         if ($(this).attr("checked")) {

              $("div.editor-field").show();                
         }
         else {
              $("div.editor-field").hide();
         }
     });
});

0

精彩评论

暂无评论...
验证码 换一张
取 消