Jquery 如何基于某些选择启用文本框

Jquery 如何基于某些选择启用文本框,jquery,html,Jquery,Html,仅当雇佣类型为合同或全职时才启用txtEmployer,应禁用全职 <div> <select id="SelectEmployment"> <option value="Select Employment">Employment Type</option> <option value="Full-time">Full-time</option> <option value="Part-ti

仅当雇佣类型为合同或全职时才启用
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>

就业类型
全职的
兼职的
合同
定期
这个怎么样

$("#SelectEmployment").change(function () {
    if ($(this).val() == "Fixed term") {
        $('#txtEmployer').attr("disabled", "disabled");
    }
    else {
        $('#txtEmployer').removeAttr("disabled");
    }
});
请尝试以下代码:

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

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

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

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

演示:

关于全职的问题是不明确的。所以,我假设第一个是兼职。试试这个:

$(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);
        }
    });
});

你有没有花时间在谷歌上搜索过这个文本框?文本框应该全部停用或激活???