테스트 사이트 - 개발 중인 베타 버전입니다

ajax에서 for문으로 html 테이블 행 증가시키기 채택완료

Sssuj 4년 전 조회 2,688

처음에는 테이블 타이틀만 존재하고 자바스크립트에서 ajax를 이용해 받은 값을 화면에 받아온 class_id의 길이만큼 for문을 돌려 행으로 출력되도록 하고싶습니다.
<tr><th>문을 ajax를 이용해 반복시키려면 어떻게 해야하나요?

 

혹시 참고할만한 사이트가 있다면 알려주시면 감사하겠습니다.

 

<tr>
<th scope="row" class="h" id="hh_0"></th>
<th class="h radio_r"><input type="radio" name="check" id="check"/></th>
</tr>

 

소스코드입니다.

</strong></p>

<p><script>

   $('input[id=kk_0]').change(function() {  </p>

<p>   var qa_id = $(this).data("qa_id");</p>

<p>   var outHtml = "";

   

   $.ajax({

      url: "title.php",

      type: "POST",

      data: {

         "qa_id": qa_id

      },

      dataType: "json",

      async: false,

      cache: false,

      success: function(data, textStatus) {

         class_id=data.Competition;

         for(i=0; i<class_id.length;i++){

           $("#hh_"+i).text(class_id[i]);

         }</p>

<p>      }

   });

      

   }); 

</script></p>

<p>   <div class="main_list_2">

      <div class="explanation">타이틀을 선택해주세요.</div>

         <form name="titleForm" class="titleForm" method="post" action="" style="width:390px; height:260px;">

            <center>

               <div style="width:390px; height:260px; overflow:auto; display: block;">

                  <table class="titleTable" width="370">

                  <thead>

                     <tr class="tableTop">

                        <th scope="cols" class="tableTitle">타이틀 리스트</th>

                        <th scope="cols"></th>

                     </tr>

                  </thead>

                  <tbody id="titleTbody">

                     <tr>

                        <th scope="row" class="h"><span id="hh_0">11</span></th>

                        <th class="h radio_r"><input type="radio" name="check" id="check" value="22"/></th>

                     </tr>

                  </tbody>

               </table>

            </div>

            <p><input type="submit" value="선택완료" class="button"></p>

         </center>

      </form>

   </div>

</div></p>

<p><strong>

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

답변을 작성하려면 로그인이 필요합니다.

로그인