2014-09-11 7 views
1

나는 혼란 스럽기 때문에 동료 개발자에게 도움을 요청합니다. 이것은 아마도 내가 간과하고있는 어떤 것일지도 모르지만, 당신이 무언가를 너무 열심히 보았을 때 당신이 어떻게 알 수 있습니다. 일반적으로 바로 거기에 있습니다. 내게서 충분한 지점으로가는 길!양식 입력 및 값 변경 숨기기/표시

나는이 응용 프로그램을 가지고 있는데, 그 응용 프로그램에 대해서만 도움이 필요합니다. 부트 스트랩 3과 함께 사용 되었기 때문에 그와 관련이 있는지 여부는 알 수 없습니다. #mail_address 체크 박스를 클릭하고 변경 사항을 확인한 다음 현재 주소 섹션 #p_address, # p_address2, #p_city, #p_state, #p_zip에서 값을 추가 할 것인지 확인합니다. 다음 입력 집합에서 각 #m_ 값을 변경 한 다음 #m_ 입력을 사용 불가능하게 변경하여 변경할 수 없도록합니다. 이 부분은 작동합니다

상자가 선택되어 있지 않으면 #mailing_address가 다시 변경되면 모든 #m_ 입력을 지우고 입력을 다시 사용 가능하게 설정하십시오. 이것은 작동하지 않을 부분입니다. 여기

이 (가) 파일 'state_list_options.php'로 문을 포함 참조 나에게이 문제

<div class='form-group'> 
       <div class='col-md-5 col-md-offset-1 col-sm-6'> 
        <div class='input-group app-input'> 
         <input type='text' class='form-control' id='p_address' placeholder='Your Current Address'> 
         <span class='input-group-addon'><span class='glyphicon glyphicon-home'></span></span> 
        </div> 
       </div> 
      </div> 
      <div class='form-group app-input-no-group'> 
       <div class='col-md-5 col-md-offset-1 col-sm-6'> 
         <input type='text' class='form-control' id='p_address2' placeholder='Current Address Line 2'> 
       </div> 
      </div> 
      <div class='form-group app-input-no-group'> 
       <div class='col-md-3 col-md-offset-1 col-sm-4'> 
        <input type='text' class='form-control' id='p_city' placeholder='Your Current City'>       
       </div> 
      </div> 
      <div class='form-group app-input-no-group'> 
       <div class='col-md-3 col-md-offset-1 col-sm-4'> 
        <select class='form-control' id='p_state'>      
         <option value="" selected>Your Current State</option> 
         <? include $up_level.'inc/body/extras/state_list_options.php';?> 
        </select> 
       </div> 
      </div> 
      <div class='form-group app-input-no-group'> 
       <div class='col-md-3 col-md-offset-1 col-sm-4'> 
        <input type='text' class='form-control' id='p_zip' placeholder='Your Current Zip'>      
       </div> 
      </div> 
      <div class='form-group'> 
       <div class='col-md-5 col-md-offset-1'> 
        <div class='checkbox'> 
         <label><input type='checkbox' id='mailing_address'>Check here if your mailing address is the same as your current address</label> 
        </div> 
       </div> 
      </div> 
      <div class='form-group'> 
       <div class='col-md-5 col-md-offset-1 col-sm-6'> 
        <div class='input-group app-input'> 
         <input type='text' class='form-control' id='m_address' placeholder='Your Mailing Address'> 
         <span class='input-group-addon'><span class='glyphicon glyphicon-home'></span></span> 
        </div> 
       </div> 
      </div> 
      <div class='form-group app-input-no-group'> 
       <div class='col-md-5 col-md-offset-1 col-sm-6'> 
         <input type='text' class='form-control' id='m_address2' placeholder='Mailing Address Line 2'> 
       </div> 
      </div> 
      <div class='form-group app-input-no-group'> 
       <div class='col-md-3 col-md-offset-1 col-sm-4'> 
        <input type='text' class='form-control' id='m_city' placeholder='Your Mailing City'>       
       </div> 
      </div> 
      <div class='form-group app-input-no-group'> 
       <div class='col-md-3 col-md-offset-1 col-sm-4'> 
        <select class='form-control' id='m_state'>      
         <option value="" selected>Your Mailing State</option> 
         <? include $up_level.'inc/body/extras/state_list_options.php';?> 
        </select> 
       </div> 
      </div> 
      <div class='form-group app-input-no-group'> 
       <div class='col-md-3 col-md-offset-1 col-sm-4'> 
        <input type='text' class='form-control' id='m_zip' placeholder='Your Mailing Zip'>      
       </div> 
      </div> 

을주고있다 형태로 조각 그래서 같은 상태 이름과 약어와 옵션을 선택 단지 목록입니다 : 여기

<option value='AZ'>Arizona</option> 

내가

$(document).ready(function(){ 
    //check if the mailing address checkbox is checked 
    //if so then we will fill the mailing address in with the information from current address then hide all the mailing address fields 
    //else clear the mailing address fields and show them again 
    //set variables 
    var p_values = ['p_address', 'p_address2', 'p_city', 'p_state', 'p_zip']; 
    var m_values = ['m_address', 'm_address2', 'm_city', 'm_state', 'm_zip']; 
    $("#mailing_address").change(function(){ 
     if($(this.checked)){ 
     //if checked get the values from the current address fields 
      for(var i = 0; i < p_values.length; i++){ 
       $('#'+m_values[i]+'').val($('#'+p_values[i]+'').val()); 
       $('#'+m_values[i]+'').attr('disabled', 'disabled'); 
      } 
     } 
     else{ 
      //this is the part that is failing 
      for(var i = 0; i < p_values.length; i++){ 
       $('#'+m_values[i]+'').val(""); 
       $('#'+m_values[i]+'').removeAttr('disabled'); 
      } 
     } 
    }); 
}); 
,691,363 그것을 함께 넣어 이름 jQuery 코드입니다210

입력에 클래스 나 이름 대신 ID를 사용한다는 것과 관련이 있습니까? 나는 그것이 중요하다고 생각하지 않는다. 나는 정말로 모르지만, 나는 절대적으로 곤란하다. 필요한 경우 자세한 정보를 추가 할 수 있습니다.

답변

2

제거 $()jsFiddle

if(this.checked){ 

당신이이

if($(this).is(':checked')){ 
+0

나는 알았다! 나는 내가 너무 오랫동안 쳐다보고있는 것이 무엇인지 간단하다는 것을 알았다! 당신은 바위 젠체하는 사람! 고맙습니다! 고맙습니다! –

+0

나는 아직 충분한 명성을 얻지 못했지만 정답이기 때문에 투표 해 주시기 바랍니다. –

1

사용 if($(this).is(':checked')){과 같을 것이다 다음의 jQuery 객체로 그것을 원한다면 this.checked 각국에서 - jQuery를에 확인하기위한 올바른 구문 .

http://jsfiddle.net/cfm1v0p7/

+1

또는'if ($ (this) .prop ('checked'))', 몇 가지 방법이 있습니다. – charlietfl

+0

그것에 대해 몰랐다 :) – heroin