Select value with on change event不会改变选项

Select value with on change event doesn't alter the option

本文关键字:改变 选项 event change value with on Select      更新时间:2023-09-26

我有一个问题,我有这个html代码

<div class="f300_sl">
   <select name="situacao_laboral" class="validate['required'] f300_sl2" onchange="alteraVencimento(this);">
<option> </option>
<option>Conta Própria</option>
<option>Prazo</option>
<option>Quadros</option>
<option>Outra</option>
  </select></div>

我的on change事件如下

    function alteraVencimento(estado){
        if(estado.value= (should be ==) 'Conta Própria'){
            document.getElementById('vencimento').innerHTML = 'Volume de Negócio:';
        }
        else{
            document.getElementById('vencimento').innerHTML = 'Vencimento:';
        }
    }

选择按钮不工作,它总是把值放在"Conta Própria"

编辑:没关系,用=代替==

抱歉。

您正在分配值而不是比较它,尝试:

function alteraVencimento(estado){
    if(estado.value == 'Conta Própria'){
        document.getElementById('vencimento').innerHTML = 'Volume de Negócio:';
    }
    else{
        document.getElementById('vencimento').innerHTML = 'Vencimento:';
    }
}

注意==而不是=

=赋值变量

==比较