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>
4

4 回答 4

0

就像是

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

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

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

演示:小提琴

于 2013-03-07T15:46:10.673 回答
0

试试下面的代码:

$("#SelectEmployment").change(function () {
    if ($(":selected", $(this)).text() == "Contract" || $(":selected", $(this)).text() == "Full-time") {
        $("#txtEmployer").removeAttr("disabled");
    } else {
        $("#txtEmployer").attr("disabled", "disabled");
    }
});
于 2013-03-07T15:45:11.847 回答
0

关于全职的问题是模棱两可的。所以,我假设第一个是兼职。尝试这个 :

$(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);
        }
    });
});
于 2013-03-07T15:53:05.883 回答
0

那这个呢?

$("#SelectEmployment").change(function () {
    if ($(this).val() == "Fixed term") {
        $('#txtEmployer').attr("disabled", "disabled");
    }
    else {
        $('#txtEmployer').removeAttr("disabled");
    }
});
于 2013-03-07T15:39:33.067 回答