2012-09-18 8 views
1

내 웹 페이지는 다음과 같습니다.Jquery - 메시지를 추가하고 이전 메시지를 지우는 방법?

<%@ 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>'); 
     }; 
  • 테이블의 체크 박스 후 메시지를 넣습니다. 내가하고 싶은 것은 이전 메시지가 존재한다면이를 지우는 것이다. 어떻게해야합니까?

답변

2

은 정의 - 당신이 메시지를 추가하기 전에

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

그것이

0

당신은이를 사용할 수있다.
$ ('오류'). 텍스트 ('');

관련 문제