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

삭제한 요소가 onsubmit에서 form 확인 시 갯수로 카운팅되고 있어요 채택완료

라균 2년 전 조회 1,514

</strong></p>

<pre>
<span>
  <select name="wr_situation" class="wr_situation">
    <option value="enteringHome">홈 화면 진입 시 띄움</option>
    <option value="completePayment">결제완료 후 띄움</option>
    <option value="completeAttendance">입장완료 후 띄움</option>
  </select><a href="#" class="remove_btn"><img src="<?= G5_URL ?>/img/remove-icon.png"/></a>
</span></pre>

<p><strong>

 

이 span 요소를 지우는것은 remove_btn 클릭시 아래 코드를 통해 지웠습니다.

</strong></p>

<pre>
$('a.remove_btn').on('click', function(e) {
  e.preventDefault();
  // Remove the parent span element when the button is clicked
  $(this).parent('span').remove();
});</pre>

<p><strong>

 

그후 해당 form을 submit 할때 onsubmit="f_onsubmit(this)" 

</strong>function f_onsubmit (f) {</p>

<pre>
console.log(f.wr_situation.length)</pre>

<p>}<strong>

갯수가 삭제 이전과 카운팅이 같습니다.

 

대신 추가 시에는 잘 적용된걸 확인했습니다.

 

삭제 후 갯수가 맞도록 하려면 어떻게 해야하나요?

 

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

답변 1개

채택된 답변
+20 포인트
c
2년 전

삭제 후 갯수를 업데이트 하려면 아래와 같이 하면 됩니다.

</strong></p>

<pre>
$('a.remove_btn').on('click', function(e) {
  e.preventDefault();
  // Remove the parent span element when the button is clicked
  $(this).parent('span').remove();
  // Update the length of the wr_situation element
  f.wr_situation.length = f.wr_situation.length - 1;
});</pre>

<p><strong>

로그인 후 평가할 수 있습니다

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

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

로그인