td의 값이 없으면 해당 tr의 특정td값 안보이게 채택완료

table 이구여 tr이 많습니다!

#answer_aq 에 값이 없을경우 

.table_input_radio label 의 내용을 dispaly:none 하고싶습니다!

방법이 있을까요?ㅠ

Copy
<tr class="tabletr">

                <td class="table_input_radio">

                    <label><input type="checkbox" name="service_end_data"><em></em></label></td>

                <td>07</td>

                <td>

                    <select>

                    </select>

                </td>

                <td id="answer_aq">

                   

                </td>

            </tr>

답변 6개

채택된 답변
+20 포인트
Copy
tr이 많습니다! <-- 이 말은 <td id="answer_aq"> 이것이 여러개 나온다는 것인데 

   id=~~이렇게 여러번 사용할 수 없습니다

같은 answer_aq가 많으면 다음처럼 class를 써야합니다

<td class="answer_aq"> 

 

자바스크립트는 다음과 같이

<script>
$('.answer_aq').each(function(){
      if( !$.trim( $(this).text() ) ) $(this).siblings().eq(0).children().hide();
});
</script>
로그인 후 평가할 수 있습니다

답변에 대한 댓글 2개

좋은답변이네요!
우와 너무 감사합니다ㅠㅠㅠ

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

php로 할 수 없는 상황인가요?

<tr class="tabletr">
                <td class="table_input_radio">
                    <label><input type="checkbox" name="service_end_data"><em></em></label></td>
                <td>07</td>
                <td>
                    <select>
                    </select>
                </td>
                <td class="answer_aq">
                   
                </td>
            </tr>
$(function(){
 $('td.answer_aq').each(function() {
  var contents = $.trim($(this).html());
  if(contents.length<1) {
    $(this).parent('tr').find('td.table_input_radio>label').hide();
  }
  });
});
로그인 후 평가할 수 있습니다

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

Copy
<table>
    <?php if($data == null){?>
    <tr>
        내용        
    </tr>
    <?php }?>
</table>

이런식으로 <tr>을 조건문으로 감싸면 될것 같습니다.

안보여야 하는 부분이 <td>라면 colspan부분도 생각하셔야 하겠죠.

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

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

Copy
$(function(){
 $('td[id="answer_aq"]').each(function() {
  var contents = $.trim($(this).html());
  if(contents.length<1) {
    $(this).parent('.tabletr').children('.table_input_radio>label').hide();
  }
  });
});

tr 값이 많군요. 위 스크립트로 적용해보세요.

그리고 W3C 사양에 id값이 중복되는건 옳지 않습니다.

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

답변에 대한 댓글 1개

아구 왜 안될까여ㅠㅠ

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

Copy
<table>
<tr class="tabletr"> <td class="table_input_radio"> <label><input type="checkbox" name="service_end_data"><em></em></label></td> <td>07</td> <td> <select> </select> </td> <td id="answer_aq"> </td> </tr>

</table>

 

<script>

function check_td(td_id){
  var contents = $.trim($(td_id).html());
  if(contents.length<1) return false
  else return true;
}

$(function(){
  if(!check_td('#answer_aq')) {
    $('.table_input_radio>label').hide();
  }
});

</script>
로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

감사합니다! 그런데 #answer_aq에 값이 있을 경우에는.table_input_radio label의 내용이 보여야하는데 전부 없어집니다ㅠ

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

$(document).ready(function() {

  if ($('#answer_aq').text() == '') {

    $('.table_input_radio label').hide()

  }

});

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

답변에 대한 댓글 1개

처음에 저도 이렇게했는데 전체가 없어지더라구요!ㅠ
tr마다 적용이 되어야합니다

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

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

로그인
🐛 버그신고