2013-03-07 4 views
0

고용 유형이 계약 또는 전체 시간 인 경우에만 txtEmployer을 사용하려면 전체 시간 동안 비활성화해야합니다.일부 선택에 따라 텍스트 상자를 사용하는 방법

<div> 
    <select id="SelectEmployment"> 
    <option value="Select Employment">Employment Type</option> 
    <option value="Full-time">Full-time</option> 
    <option value="Part-time">Part-time</option> 
    <option value="Contract">Contract</option> 
    <option value="Fixed term">Fixed term</option> 
    </select> 
</div> 
<div> 
    <input type="text" id="txtEmployer" value="Employer" class="txtinline water"/> 
</div> 
+3

언제든지이 시간을 보냈습니까? –

+0

풀 타임으로 텍스트 상자를 비활성화하거나 활성화해야합니까 ??? –

답변

0

문제는 full-time.So에 대한 모호, 내가 먼저 하나를 가정 하였다 파트 타임. 사용해보기 :

$(document).ready(function(){ 
    $('#SelectEmployment').change(function(){ 
     if($(this).val() == 'Contract' || $(this).val() == 'Part-time') { 
      $('#txtEmployer').removeAttr('disabled'); 
     } 
     if($(this).val() == 'Full-time') { 
      $('#txtEmployer').attr('disabled', true); 
     } 
    }); 
}); 
0

코드 아래

$("#SelectEmployment").change(function() { 
    if ($(this).val() == "Fixed term") { 
     $('#txtEmployer').attr("disabled", "disabled"); 
    } 
    else { 
     $('#txtEmployer').removeAttr("disabled"); 
    } 
}); 
0

시도 :

$("#SelectEmployment").change(function() { 
    if ($(":selected", $(this)).text() == "Contract" || $(":selected", $(this)).text() == "Full-time") { 
     $("#txtEmployer").removeAttr("disabled"); 
    } else { 
     $("#txtEmployer").attr("disabled", "disabled"); 
    } 
}); 
0

뭔가

function updateState(val){ 
    $('#txtEmployer').prop('disabled', !(val == 'Full-time' || val == 'Contract')); 
} 

$('#SelectEmployment').change(function(){ 
    var val = $(this).val(); 
    updateState(val); 
}); 

updateState($('#SelectEmployment').val()); 

같은 데모 : Fiddle

관련 문제