2016-11-17 77 views
1

我有一個jsp和想用scriplet禁用下拉列表中,而不在下拉菜單中任何的onclick方法或事件禁用下拉列表

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

怎麼做?請提出任何提示?

+0

您將需要在線小腳本,比如'禁用=「<%=東西%>「',JavaEL像'disabled =」$ {something}「'或者在if和el中有不同的select聲明E-分支機構。 – Thomas

+0

不,在這種情況下,無論是真是假,總是禁用 –

回答

-1
<% 
     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" > 

現在,它的工作謝謝

1

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

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

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

其不工作 –

+0

@FatimaEman我經常使用它。它應該工作。檢查瀏覽器中的html代碼。 http://www.w3schools.com/TAgs/att_select_disabled.asp – dit

+0

我已經在Mozila和Chrom兩個瀏覽器中檢查過。他們總是顯示啓用下拉,無論是虛假還是真實的 –