2012-03-26 2 views
0

나는 textfield을 가지고 있으며 textfieldhold three charactes이 아닌 경우 제출 버튼을 비활성화합니다. 내가 지금하고 싶은 것은 textfield굵은 빨간색의 윤곽선이며 여전히 submit 버튼이 비활성화되어 있습니다. 그러나 textfield의 윤곽선을 그릴 수 없으며 동시에 button을 제출할 수없는 것으로 보입니다.오류를 표시하는 jQuery 개요 텍스트 필드

제출 버튼을 사용 중지하기위한 코드는 다음과 같습니다. textfield의 경우이 기능을 수행 할 때 length is < 3의 윤곽을 그릴 수 있습니까? 어떤 도움 thankfull

$(function() { 

     $('input[name="updateMessage"]').attr('disabled','disabled'); 
     $('input[name="selectMessageForUpdate"]').keyup(function(){ 
      if($('input[name="selectMessageForUpdate"]').val().length < 3) 
      { 
       $('input[name="updateMessage"]').attr('disabled','disabled'); 
      } 
      else 
      { 
       $('input[name="updateMessage"]').removeAttr('disabled'); 
      } 
     }); 

    }); 

답변

0

은 CSS에서, attr('disabled')

는 빨간색 테두리를 정의하는 클래스를 추가와 함께 border CSS 속성을 추가

textarea[name=selectMessageForUpdate].disabled { border:5px solid red } 

당신의 js를 :

$(function() { 

     $('input[name="updateMessage"]').attr('disabled','disabled'); 
     $('textarea[name="selectMessageForUpdate"]').keyup(function(){ 
      if($(this).val().length < 3) 
      { 
       $('input[name="updateMessage"]').attr('disabled','disabled'); 
       $(this).addClass('disabled'); // ADD THIS 
      } 
      else 
      { 
       $('input[name="updateMessage"]').removeAttr('disabled'); 
       $(this).removeClass('disabled'); // ADD THIS 
      } 
     }); 

    }); 

은 내가 JS 바이올린을 생성하며

http://jsfiddle.net/tmjaF/8/

+0

아 예이는 작동 버튼을하지만 난 윤곽을 싶습니다 'textfield' 문자가'<3' @andreas 인 경우 – CodersSC

+0

ok 내 대답을 편집했습니다 –

+0

흠 이것은 여전히 ​​작동하지 않습니다 :/ – CodersSC

0

그는 버튼을 제출하지, 텍스트 영역의 스타일을하고 싶어 ... 작동하는 것 같다. 지정된 마크 업으로 클래스를 텍스트 영역에 추가하고 입력이 유효 할 때이를 제거하십시오. 또한 입력이 공백 이외의 다른 것인지 확인하십시오.

$(function() { 
    $('input[name=updateMessage]').attr('disabled','disabled'); 
    $('input[name=selectMessageForUpdate]').keyup(function(){ 
     if($('input[name=selectMessageForUpdate]').val().length < 3) 
     { 
      $('input[name=updateMessage]').attr('disabled','disabled'); 
      $('input[name=selectMessageForUpdate]').addClass('someClass'); 
     } 
     else 
     { 
      $('input[name="updateMessage"]').removeAttr('disabled'); 
      $('input[name=selectMessageForUpdate]').removeClass('someClass'); 
     } 
    }); 

}); 
0

것은 당신의 CSS에 추가

input.indicated_textfield { border: 2px solid red; } 

당신의 자바 스크립트 코드에 addClass 및 removeClass 줄을 추가

$(function() { 

    $('input[name="updateMessage"]').prop('disabled', true); 
    $('input[name="selectMessageForUpdate"]').keyup(function(){ 
     if($('input[name="selectMessageForUpdate"]').val().length < 3) 
     { 
      $('input[name="updateMessage"]').prop('disabled', true); 
      $('input[name="selectMessageForUpdate"]').addClass('indicated_textfield'); 
     } 
     else 
     { 
      $('input[name="updateMessage"]').prop('disabled', false); 
      $('input[name="selectMessageForUpdate"]').removeClass('indicated_textfield'); 
     } 
    }); 

}); 
+0

jquery-1.7.2.js @elaxsj를 사용하고 있습니다. – CodersSC

+0

jQuery 1.6.1+에서는 attr/removeAttr 대신 prop 메소드를 사용해야한다. prop 메소드는 1.6.1에서 새로 추가되었으며 페이지가로드 된 후 속성을 변경하는 데 사용됩니다.나는 그에 따라 코드를 업데이트했다 : – elaxsj

+0

그 덕분에, 장애인은 여전히 ​​작동하지만'textfield'에 대한 윤곽이 작동하지 않는다 :/나는'CSS'가로드되었는지 확인했지만 여전히'textfield '@elaxsj – CodersSC

관련 문제