2017-01-01 1 views
-2

사용자 이름, 전자 메일 또는 암호 필드 또는 모두가 비어 있고 사용자가 모두 채우면 제출 버튼을 활성화 할 때 양식의 제출 버튼을 비활성화하려고합니다. 하지만 다음 코드는 제출 버튼을 비활성화하지 않습니다.다음 jquery 코드가 제출 버튼을 비활성화하지 않는 이유는 무엇입니까?

감사

HTML 코드

:

<form id="new_user_form"> 
             {% csrf_token %} 
            <div class="modal-content" data-method="post" id="modalform" > 
              <div class="modal-header"> 
               <button type="button" class="close" data-dismiss="modal">&times;</button> 
               <h4 class="modal-title">Sign Up</h4> 
              </div> 
             <div onload="validateForm();" class="modal-body"> 
              <div class="form-group"> 
               <label for="usr">Username:</label> 
               <input type="text" name="username" class="form-control input-sm" id="username"> 
               <label for="eml">Email:</label> 
               <input type="email" name="emil" class="form-control input-sm" id="emailid"> 
               <label for="passwordd">Password:</label> 
               <input onchange="checkPasswordMatch();" type="password" name="password" class="form-control input-sm" id="password"> 
               <label for="passwordd">Retype Password:</label> 
               <input type="password" name="retrypassword" class="form-control input-sm" id="retrypassword"> 
               <br/><div style="color:blue;" id="doesPasswordMatch"> </div> 
               <span class="help-block">Ensure, You Choose Correct Profession...</span> 

             <label for="inputfile">Upload Profile Picture</label> 
             <input type="file" id="inputfile"> 
             <p class="help-block">The Profile Picture help people to identify you.</p> 
              </div role="Form group"> 
              </div role="modal-dialog"> 
         <!--Closing Of Sign Up Modal Page --> 
               <div class="modal-footer"> 
                   <button type="submit" class="btn btn-default" id="submit" onclose="showSuccessMessage();">Submit</button> 
                   <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
               </div role="modal-footer"> 
            </div role="modal content"> 

jQuery 코드 :

<script type="text/javascript"> 
    function checkPasswordMatch() { 
     if ($('#password').val() == $('#retrypassword').val()) 
      $('#doesPasswordMatch').html("<h4> Match </h4>").css('color', 'rgb(34,139,34)'); 
     else 
      $('#doesPasswordMatch').html("<h4> Does not match </h4>").css('color', 'rgb(128,0,0)'); 

    } 
    $(document).ready(function() { 
     $('#submit').attr('disable', true); 
     $('#retrypassword').keyup(checkPasswordMatch); 
     if ($('#username').val() == '' || $('#email').val() == '' || $('#password').val() == '') 
      $('#submit').attr('disable', false); 
    }); 
</script> 
+0

'attr' 대신'prop'e – Musa

+0

@Musa : jQuery가 당신을 위해 고쳐주기 때문에'attr'가 작동 할지라도 꽤 사실입니다. –

+0

그리고 비활성화되지 않음 – sheavens

답변

3

속성은 (마지막에 d와) disabled이다,하지 disable. 그것은 disabled해야하며

disable이 일을해야하지

$("#submit").prop("disabled", true); 
// ----------^^^^---------^ 
+0

그것은 아직도 작동하지 않으며 무엇을 위해 downvoting 이는 ??? – Ahtisham

+0

@Ahtisham : 여전히 작동하지 않으면 코드에 * 다른 문제가 있습니다. 이것은 밖으로 튀어 나온 명백한 것 (잘, 2)입니다. 디버거를 사용하여 코드를 단계별로 실행하고 변수 등을 조사하십시오. –

1

: attr 역사적인 이유로 당신을 위해 이것을 처리 할 수 ​​있지만, 그것은을 설정하는 올바른 방법은 prop 경유

$('#submit').attr('disabled',true); 

또는

$('#submit').attr("disabled","disabled"); 
+0

여전히 작동하지 않으며 무엇이 downvoting입니까 ??? – Ahtisham

+0

나는 당신의 질문을 downvote하지 않았다. 다른 것은 가지고 있을지도 모른다. –

+0

괜찮은 broda가 당신을 위해 내 표를 간다 :)하지만 여전히 작동하지 않습니다 : ( – Ahtisham

관련 문제