본문 바로가기

.NET/ASP.NET

Jquery before 메서드 사용하기

오늘 주어진 작업을 하다 보니 ....

디비에 html 템플릿이  있어 템플릿 데이터를 가져와 그 html을 각각의 요소에 정해진 field를  디비값으로

replace하는 형식의 페이지를 봤다.  내 주어진 업무는 템플릿 안에 특정 데이터를 삽입하는 거다.

어떻게 했을까?  에라 귀찮다. jquery를 썼다.

상세한 업무 내용은 submit버튼 위에 고객의 댓글을 삽입하는 거다.

난 submit버튼에 고우의 아이디를 주고 그 엘러먼트 전에

고객의 댓글을 삽입하기로 했다.

구체적인 코딩은 아래와 같다. 

1.자바스크립트
 <script type="text/javascript">
            $(document).ready(function () {
                var reviewDisplay = "<%= ReviewShouldBeVisible%>";
                if (reviewDisplay == 'True') {
                    var html = $('#review').html();
                    $('.btn_order').before(html);
                   }
            });
        </script> 


 2.html
<%if (ReviewShouldBeVisible) %>
   <%{ %>
        <div style="display:none">
        <li id="review">
            <!-- 수강후기 시작 -->
            <div class="review">
                <div style="margin: 40px 0 0 0;">
                    <img src="http://img.hunet.co.kr/event/2011/newEdu/0727_account/img_17.jpg"></div>
                <div style="margin: 0 0 15px 0; text-align: right;">
                    <a href="http://www.hunet.co.kr/Education/Detail.aspx?gid=<%=goodsId %>&itype=1">
                        <img alt="더보기" src="http://img.hunet.co.kr/event/2011/newEdu/0727_account/btn_more.gif"></a></div>
                <table width="100%" cellspacing="0" cellpadding="0" border="0" class="list">
                    <tbody>
                    <asp:Repeater ID="ReviewTextRepeater" runat="server">
                    <ItemTemplate>
                        <tr>
                            <th width="89%">
                                <%# FrontPage.GetMaskedUserId(Eval("UserNm", null), 2, "*")%> (<%# FrontPage.GetMaskedUserId(Eval("RegId", null))%>)
                            </th>
                            <th width="11%" class="num">
                               <%#Eval("RegDate", "{0:yyyy.MM.dd}")%>
                            </th>
                        </tr>
                        <tr>
                            <td colspan="2">
                                  <%#Fusion.Framework.Util.StringUtility.ConvertToHtml(Eval("ContentTxt", null))%>
                            </td>
                        </tr>   
                        </ItemTemplate>
                        </asp:Repeater>                    
                    </tbody>
                </table>
            </div>
            <!-- 수강후기 끝 -->
        </li>    
        </div>
        <%} %>