2014-09-03 1 views
-5

내 코드에서 무슨 일이 일어나고 있는지 이해할 수 없습니다. 확인란을 선택하면 모달 상자를 표시하려고합니다. 모달 상자를 표시하지만 확인란을 선택하지 않은 채로 유지하십시오. 도와 주시겠습니까? 미리 감사드립니다. 당신은 당신이 할 수있는 동일한 개체의 경우에이 기능을 사용할 수 있도록모달 상자를 표시 한 후 확인란을 선택하는 방법은 무엇입니까?

$("#mantenerhorario").attr('checked', true); 

$("#mantenerhorario").prop('checked', true); 

될해야 소품 기능을 사용합니다 체크 박스와 함께 사용하기 위해

<td colspan="3"><input class="solo{{idioma.id}}" type="checkbox" id="mantenerhorario" name="mantenerhorario" {% if mantenerhorarioanterior == 1 %} checked {% endif %} 
data-target="#myModal" data-toggle="modal" > Mantener horario del año anterior</td> 

$("#mantenerhorario").click(function(){ 
     $('body').append('<div id="modalMantenerHorario" class="modal hide fade" role="dialog" 
     aria-labelledby="dataConfirmLabel" aria-hidden="true"> 
     <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
     <h3 id="myModalLabel">Aviso</h3></div><div class="modal-body"><p>my msg.</p></div> 
     <div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true">Aceptar</button></div></div>'); 
     $('#modalMantenerHorario').find('.modal-body').text($(this).attr('data-confirm')); 
     $('#modalMantenerHorario').modal({show:true}); 
     $("#mantenerhorario").attr('checked', true); 
    }); 
+1

* "확인란을 선택했을 때 모달 상자를 표시하고 확인란을 선택하십시오."- 이해가되지 않습니다. 모델을 보여 주려고 이미 확인한 다음 다시 확인해야하는 이유는 무엇입니까? –

+0

내 확인란은 모달 상자를 표시하지만 확인란을 선택하지 않습니다. 이해하니? – Freenando

+0

@TJ 그는 모달 상자를 터뜨린 후 그의 체크 박스가 계속 확인되지 않는다는 것을 의미합니다. – AlexGreg

답변

1

$(this).prop('checked', true); 
+0

감사합니다. Telmo, 전 당신의 코드를 테스트했지만 작동하지 않습니다. 매우 이상합니다. – Freenando

+0

코드를 확인했습니다. 입력 태그를 닫지 않았습니다. 아마 그럴거야. 또한 확인란과 함께 기능을 사용해야합니다. –

0

찾았 어!

나는

데이터를 대상 = "#의 myModal"데이터 토글 =

<input class="solo{{idioma.id}}" type="checkbox" id="mantenerhorario" name="mantenerhorario" 
{% if mantenerhorarioanterior == 1 %} checked {% endif %} data-target="#myModal" 
data-toggle="modal" > 

여기에서

"모달"코드의이 부분을 제거하고 그것은 작동 .

<input class="solo{{idioma.id}}" type="checkbox" id="mantenerhorario" name="mantenerhorario" 
{% if mantenerhorarioanterior == 1 %} checked {% endif %}> 

$("#mantenerhorario").click(function(){ 
    $('body').append('<div id="modalMantenerHorario" class="modal hide fade" role="dialog" 
    aria-labelledby="dataConfirmLabel" aria-hidden="true"> 
    <div class="modal-header"> 
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
    <h3 id="myModalLabel">Aviso</h3></div><div class="modal-body"><p>my msg.</p></div> 
    <div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true">Aceptar</button></div></div>'); 
    $('#modalMantenerHorario').find('.modal-body').text($(this).attr('data-confirm')); 
    $('#modalMantenerHorario').modal({show:true}); 

}); 
관련 문제