2013-03-07 68 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

你花了多少時間使用Google? – 2013-03-07 15:40:16

+0

文本框應該全部停用或激活? – 2013-03-07 15:44:48

回答

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

相關問題