2017-05-15 1 views
0

내가 장고에 응용 프로그램을하고 난 내 모델을 업데이트 선택 인 경우 체크 박스는 반응하지 않았다. 템플릿에서장고 템플릿

내가 가진 :

<h2>Promoted post</h2> 
    <label>Promoted post?</label> 
    {{ form.is_promoted_post }} 
    <br><br> 

    <label>Promoted date from</label> 
    {{ form.promoted_from }} 

    <label>Promoted date to</label> 
    {{ form.promoted_to }} 

    <label>Promoted budget</label> 
    {{ form.promoted_budget }} 

내가 is_promoted_post에 대한 자세한 내용을 얻을 수 방화범을 사용할 때 내가 얻을 :

<input checked="checked" id="id_is_promoted_post" name="is_promoted_post" type="checkbox"> 

내 JS 코드를 시작 할 시도했지만 코드가 응답하지 않았습니다 때 모델을 저장하지 않고 선택된 확인란.

내 JS 코드 : 어떤 도움

$(document).ready(function(){ 
     if ($('input#id_is_promoted_post').prop('checked')) { 
     alert('Test test'); 
     } 
    }); 

감사합니다.

답변

0

이보십시오. 그래서 당신은 또한 다음과 같은 코드를 시도 할 수 있습니다 : 당신의 게시물에 대한

$(document).ready(function(){ 
    if ($('#id_is_promoted_post').is(':checked')) { 
    alert('Test test'); 
    } 
}); 
+0

나를 위해 일합니다. 고맙습니다. +1 – Kai

1

보십시오 : 당신이 check/uncheck

$('#id_is_promoted_post').change(function() { 
    if(this.checked) { 
     alert("checked") 
     return false; 
    } 
    alert("unchecked")  
}); 
+0

안녕 @henrym 감사하지만, 아니. – Kai

0

$('#id_is_promoted_post').is(':checked') 다르게 checkbox이 선택됩니다 경우 true 또는 false를 반환합니다 트리거하려면

$(document).ready(function(){ 
    if ($('#id_is_promoted_post').prop('checked')) { 
    alert('Test test'); 
    } 
});