在没有任何事件的情况下禁用下拉列表

Disable dropdown list without any event

我有一个 jsp 并且想在下拉菜单中没有任何 onclick 方法或事件的情况下使用 scriplet 禁用下拉列表

         <%
                boolean something= true;
                if(something){
      // here I want to get plc1 using id and want to disable it if it is true
                }else{
//do some thing
}
            %>

我的下拉菜单 html 代码在这里

<td bgcolor='' align="center" ><select id = "plc1" name="place1" onclick="this.parentNode.style.backgroundColor = this.value">
                     <option value='red'>Park here</option>
                     <option value='green'>Cancel</option>
                        </select></td>

怎么做?有什么提示吗?

只需使用 disabled 属性:<select id="plc1" disabled>

<%
    String state = "";
    if(something){
        state = "disabled";
    }
%>

<select id="plc1" <%= state %>>
<%
        boolean something=false;
        String state = "";
        if(something){
            state = "disabled";
            // here I want to get plc1 using id and want to disable it if it is ture
        }else{
           state = "enable"; 
        }
        %>

Html

<select <%= state %> id = "plc1" >

现在可以使用了谢谢