1

我的网页如下;

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<SHP.Models.AdditionalDepartmentsViewModel>" %>
<%@ Import Namespace="SHP.Helpers" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Additional Departments</title>
</head>
<body>
    <p>For SHP <%: Model.Employee.Forename %> <%: Model.Employee.Surname %> has been assigned to 
        <%: Model.Employee.BusinessUnit.BusinessUnitName %>.</p>
    <p>For MNet <%: Model.Employee.Gender.GetThirdPersonSingularPronoun()%> you can assign the Departments here as well.</p>
    <div id="TableBusinessUnits">
        <div id="leftSide">
            <table>
                <tr>
                    <th>Departments</th>
                    <th></th>
                </tr>
                <%: Html.EditorFor(model => model.Departments) %>
            </table>
        </div>
        <div id="rightSide" style="padding-right:50px;">
            <table>
                <tr>
                    <th>Divisions</th>
                    <th></th>
                </tr>
                <%: Html.EditorFor(model => model.Divisions) %>
            </table>                        
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
    $(document).ready(function () {
        var elementId;
        $('tr input[type="checkbox"]').click(function () {
            elementId = $(this).attr('id');
            var url = $(this).attr('data-url');
            var employeeId = $(this).attr('data-employeeId');
            var businessUnitId = $(this).attr('data-businessUnitId');
            var selectedFlag = $(this).is(':checked');

            dataService.saveSelection(
            employeeId,
            businessUnitId,
            selectedFlag,
            elementId,
            SavedSetting,
            url
        );
        });
    });

    SavedSetting = function (data) {
        $(data.ElementId).after('<span class="error">' + data.Message + '</span>');
    };
</script>

EditorFor 命令为此编辑器模板提供循环;

<tr>
    <td><%: Model.BusinessUnit.BusinessUnitName %></td>
    <td>
    <%: Html.CheckBoxFor( 
            x => x.Selected,
            new RouteValueDictionary 
            { 
                { "data-url", Url.Action("AddBusinessUnitForEmployee", "DataService") }, 
                { "data-employeeId", Model.EmployeeId }, 
                { "data-businessUnitId", Model.BusinessUnit.BusinessUnitId } 
            } 

       ) %> 

    </td>
</tr>

上面的最后一段 JQuery -

SavedSetting = function (data) {
            $(data.ElementId).after('<span class="error">' + data.Message + '</span>');
        };
  • 在表格中的复选框之后放置一条消息。我想做的是清除上一条消息(如果存在)。我怎么做?
4

2 回答 2

2

定义 -

$('.error').empty();

在其中添加消息之前

于 2012-09-18T09:45:22.230 回答
0

你也可以使用这个。
$('.error').text('');

于 2012-09-18T10:01:29.573 回答