Javascript 如何从“选择”下拉列表中删除重复值?

Javascript 如何从“选择”下拉列表中删除重复值?,javascript,jquery,jsp,html.dropdownlistfor,Javascript,Jquery,Jsp,Html.dropdownlistfor,这是我的jsp代码: <form method="post" action="" > <table style="width: 100%;border: 0px;border-spacing: 0px;padding: 0px;"> <tr> <td style="height: 28px; font-size: 14px; width:80px; ">Select State :</td> <

这是我的jsp代码:

<form method="post" action="" >
    <table style="width: 100%;border: 0px;border-spacing: 0px;padding: 0px;">
    <tr>

    <td style="height: 28px; font-size: 14px; width:80px; ">Select State :</td>

    <td style="text-align: left; padding-left: 10px; width: 450px;">  
        <select name="city"  onchange="Consituteshow(this.value)">  
                    <option value="">Andhra Pradesh</option>  
                    <%
                                            Statement stmt=null;
                                            DBconnection db=new DBconnection();
                                            Connection con=db.dbConn();
                                            try{
                                            stmt = con.createStatement();  
                                            ResultSet rs = stmt.executeQuery("select distinct StateID,State from election_history;");
                                            while(rs.next())
                                            {
                      %>

                                           <option value="<%=rs.getString(2)%>"><%=rs.getString(2)%></option>  

                     <%}%>

      </select>
    </td>

  </tr>

</table>
</form>

选择状态:
安得拉邦
以上是我的jsp代码,在此代码中,我已将“安得拉邦”作为默认名称。由于此内部下拉列表,“安得拉邦”打印了两次。是否有方法删除它???

检查名称是否为“安得拉邦”,如果是,则使用
selected=“selected”


}否则{
}
}
%>

将while语句中的所有内容包装为:

见此:


if(rs.getString(2)!=“安得拉邦”){…}
您可以编写查询

  select distinct StateID,State from election_history where State != 'Andhra Pradesh'
或者您可能需要使用
jQuery.unique()
method


 <select name="city"  onchange="Consituteshow(this.value)">  
                <%   
  Statement stmt=null;
  DBconnection db=new DBconnection(); 
  Connection con=db.dbConn();
   try{  
    stmt = con.createStatement();  
    ResultSet rs = stmt.executeQuery("select distinct StateID,State from election_history;");
    while(rs.next()){
                 if(!rs.getString(2).equals("Andhra Pradesh")){
                  %>
            <option value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option>  
                 <%}else{%>
<option selected='selected' value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option>  
    <%}
}%></select>

您能否显示您的实际HTML,而不是用于生成HTML的脚本?那么您为什么不提供
安得拉邦
选项的值?为什么我的问题被否决?有人能解释我吗?如果我的问题不清楚,您如何回答?有人能回答我吗??
 <select name="city"  onchange="Consituteshow(this.value)">  
                <%   
  Statement stmt=null;
  DBconnection db=new DBconnection(); 
  Connection con=db.dbConn();
   try{  
    stmt = con.createStatement();  
    ResultSet rs = stmt.executeQuery("select distinct StateID,State from election_history;");
    while(rs.next()){
                 if(!rs.getString(2).equals("Andhra Pradesh")){
                  %>
            <option value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option>  
                 <%}else{%>
<option selected='selected' value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option>  
    <%}
}%></select>