如何在下拉列表中启用多个条件


How to enable more than one condition in dropdown list?

我有一个下拉列表。当我选择"Others"时,"Other Action textbox"将启用。
当我选择"课堂培训""在职培训(OJT)"时,下拉"拟议的Ilsas培训"和文本框"拟议的公共培训"将启用。
对于"Others"条件,我已经做对了。

那么,如何在JavaScript中添加另一个条件呢?这是因为我试图将这些条件合并到JavaScript中,但没有成功。

<script language="javascript" type="text/javascript"> 
    function otherAction(val) {
        var otherAct = document.getElementById('otherAct');
        if(val=='Others') {
            otherAct.style.display = "block";
        } else {    
            otherAct.style.display = "none";
        }
    }
</script>
<table>
    <tr>
        <td>Action: </td>
        <td>
            <select name="perAction" onchange="otherAction(this.value)"> 
                <option value="0"></option>                    
                <option value="Classroom Training">Classroom Training</option>
                <option value="Coaches and Mentoring by IM">Coaches and Mentoring by IM</option>
                <option value="On Job Training (OJT)">On Job Training (OJT)</option>
                <option value="Others">Others</option>
            </select>
        </td>
        <td>Other Action: </td>
        <td><input name="otherAct" type="text" id="otherAct" /></td>
        <td>Proposed Training in Ilsas: </td>
        <td>
            <select name = "perIlsas">
                <option value="0"></option>                    
                <option value="Project Management">Project Management</option>
                <option value="Contract Management">Contract Management</option>
                <option value="Analytical Skill">Analytical Skill</option>
            </select>
        </td>
        <td>Proposed Training in Public: </td>
        <td><input name="pubTraining" type="text" id="pubTraining" /></td>
    </tr>
</table>

你只需要使用多个if-else条件

<script language="javascript" type="text/javascript"> 
    function otherAction(val) {
        var otherAct = document.getElementById('otherAct');
        if(val=='Others') {
            otherAct.style.display = "block";
        } else if(val == 'On Job Training (OJT)'){    
             otherAct.style.display = "none";
             pubTraining.style.display = "block";
            // set display here either `block` or `none` according to your need
        }
        else{
             // set display here either block or none according to your need
        }
    }
</script>
编辑:

首先给这个选择框一个id属性。然后,您可以编写另一个else-if条件检查,如

<select id="perIlsas" name = "perIlsas"> //assigning id attribute
else if(val == 'Coaches and Mentoring by IM'){ //another else-if condition    
       $('#perIlsas').prop('disabled', 'disabled'); //this will disable entire selectbox
        }

您可以在jQuery文档

中了解更多关于prop的信息。