简体   繁体   English

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

[英]How to enable more than one condition in dropdown list?

I have one dropdown list. 我有一个下拉列表。 When I select "Others" , "Other Action textbox" will enable. 当我选择“其他”时 ,将启用“其他操作文本框”
When I select "Classroom Training" or "On Job Training(OJT)" , dropdown "Proposed Training in Ilsas" and textbox "Proposed Training in Public" will enable. 当我选择“课堂培训”“在职培训(OJT)”时 ,下拉菜单“在Ilsas的建议培训”和文本框“在公共 场所的 建议培训”将启用。
For the "Others" condition I have made it right. 对于“其他”条件,我已经说对了。

Then, how can I add another conditions into JavaScript? 然后,如何在JavaScript中添加其他条件? This is because I have tried to combine the conditions into JavaScript but it's not successful. 这是因为我试图将条件合并到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> 

You just have to use multiple if-else conditions 您只需要使用多个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>

EDIT: First of all give some id attribute to that select box. 编辑:首先给该选择框一些id属性。 and then,You can write another else-if condition checking like this 然后,您可以编写另一个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
        }

You can get to know more about prop in the jQuery Docs 您可以在jQuery Docs中了解有关prop更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM