有5个DropDownList 值都是从数据库读出来的
我现在要添加文章 这篇文章同时属于3个类别
现在我想判断一下 如果这5个DropDownList 中的两个选得一样 我就提示错误
代码怎么写 谢谢

解决方案 »

  1.   

    最好别用js 因为我不懂js 谢谢
      

  2.   

    在客户端DropDownList的onchange事件里判断 各个drpObj.value里是否有相同的值
    不懂可以学.....
      

  3.   

    <select id='dw1'>
    <option value="111111">111111</option>
    <option value="222222">222222</option>
    <option value="333333">333333</option>
    <option value="444444">444444</option>
    <option value="555555">555555</option>
    </select>
    <select id='dw2'>
    <option value="111111">111111</option>
    <option value="222222">222222</option>
    <option value="333333">333333</option>
    <option value="444444">444444</option>
    <option value="555555">555555</option>
    </select>
    <select id='dw3'>
    <option value="111111">111111</option>
    <option value="222222">222222</option>
    <option value="333333">333333</option>
    <option value="444444">444444</option>
    <option value="555555">555555</option>
    </select>
    <select id='dw4'>
    <option value="111111">111111</option>
    <option value="222222">222222</option>
    <option value="333333">333333</option>
    <option value="444444">444444</option>
    <option value="555555">555555</option>
    </select>
    <select id='dw5'>
    <option value="111111">111111</option>
    <option value="222222">222222</option>
    <option value="333333">333333</option>
    <option value="444444">444444</option>
    <option value="555555">555555</option>
    </select>
    <input type="button" value="Check" onclick="CheckDW()" />
    <script>
    function $(id){return document.getElementById(id);}
    function CheckDW()
    {
      var dw;
      for(var i=1;i<5;i++)
      {
        dw=$("dw"+i);
        for(var j=i+1;j<=5;j++)
        {
          if($("dw"+j).value==dw.value)
          {
            alert('有重复的...');
            return false;
          }
        }
      }
    }
    </script>
      

  4.   


    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CheckBox.WebForm1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <span id="ddl">
            <asp:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem>a</asp:ListItem>
                <asp:ListItem>b</asp:ListItem>
                <asp:ListItem>c</asp:ListItem>
                <asp:ListItem>d</asp:ListItem>
                <asp:ListItem>e</asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList ID="DropDownList2" runat="server" Style="position: relative">
                <asp:ListItem>a</asp:ListItem>
                <asp:ListItem>b</asp:ListItem>
                <asp:ListItem>c</asp:ListItem>
                <asp:ListItem>d</asp:ListItem>
                <asp:ListItem>e</asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList ID="DropDownList3" runat="server" Style="position: relative">
                <asp:ListItem>a</asp:ListItem>
                <asp:ListItem>b</asp:ListItem>
                <asp:ListItem>c</asp:ListItem>
                <asp:ListItem>d</asp:ListItem>
                <asp:ListItem>e</asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList ID="DropDownList4" runat="server" Style="position: relative">
                <asp:ListItem>a</asp:ListItem>
                <asp:ListItem>b</asp:ListItem>
                <asp:ListItem>c</asp:ListItem>
                <asp:ListItem>d</asp:ListItem>
                <asp:ListItem>e</asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList ID="DropDownList5" runat="server" Style="position: relative">
                <asp:ListItem>a</asp:ListItem>
                <asp:ListItem>b</asp:ListItem>
                <asp:ListItem>c</asp:ListItem>
                <asp:ListItem>d</asp:ListItem>
                <asp:ListItem>e</asp:ListItem>
            </asp:DropDownList>
            </span>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="position: relative"
                Text="Button" /></div>
        </form>
        
        
    </body>
    </html>
    [code=C#]
      protected void Button1_Click(object sender, EventArgs e)
            {
                string[] str = new string[5];
                str[0] = this.DropDownList1.SelectedItem.Text;
                str[1] = this.DropDownList2.SelectedItem.Text;
                str[2] = this.DropDownList3.SelectedItem.Text;
                str[3] = this.DropDownList4.SelectedItem.Text;
                str[4] = this.DropDownList5.SelectedItem.Text;            for (int i = 0; i < str.Length-1; i++)
                { 
                    for(int j=1;j<str.Length;j++)
                    {
                        if(str[i]==str[j])
                        {
                            Response.Write("有相同");
                            break;
                        }
                    }
                }        }[/code]
      

  5.   

    上面那個有問題  再發個客戶端的
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CheckBox.WebForm1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <span id="ddl">
            <asp:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem>a</asp:ListItem>
                <asp:ListItem>b</asp:ListItem>
                <asp:ListItem>c</asp:ListItem>
                <asp:ListItem>d</asp:ListItem>
                <asp:ListItem>e</asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList ID="DropDownList2" runat="server" Style="position: relative">
                <asp:ListItem>a</asp:ListItem>
                <asp:ListItem>b</asp:ListItem>
                <asp:ListItem>c</asp:ListItem>
                <asp:ListItem>d</asp:ListItem>
                <asp:ListItem>e</asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList ID="DropDownList3" runat="server" Style="position: relative">
                <asp:ListItem>a</asp:ListItem>
                <asp:ListItem>b</asp:ListItem>
                <asp:ListItem>c</asp:ListItem>
                <asp:ListItem>d</asp:ListItem>
                <asp:ListItem>e</asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList ID="DropDownList4" runat="server" Style="position: relative">
                <asp:ListItem>a</asp:ListItem>
                <asp:ListItem>b</asp:ListItem>
                <asp:ListItem>c</asp:ListItem>
                <asp:ListItem>d</asp:ListItem>
                <asp:ListItem>e</asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList ID="DropDownList5" runat="server" Style="position: relative">
                <asp:ListItem>a</asp:ListItem>
                <asp:ListItem>b</asp:ListItem>
                <asp:ListItem>c</asp:ListItem>
                <asp:ListItem>d</asp:ListItem>
                <asp:ListItem>e</asp:ListItem>
            </asp:DropDownList>
                <input id="Button1" style="position: relative" type="button" value="button" onclick="return check()" /></span></div>
        </form>
        
        <script type="text/javascript">
            function check()
            {
                var inputs=document.getElementById("ddl").getElementsByTagName("select");
                for(var i=0;i<inputs.length-1;i++)
                {
                    for(var j=i+1;j<inputs.length;j++)
                    {
                        if(inputs[i].options[inputs[i].selectedIndex].value==inputs[j].options[inputs[j].selectedIndex].value)
                        {
                            alert("有相同值");
                            return false;
                        } 
                    }
                }
            }
        </script>
    </body>
    </html>
      

  6.   

    同意并引用7楼的,做点小改动。HTML code<select id='dw1'>
    <option value="111111">111111</option>
    <option value="222222">222222</option>
    <option value="333333">333333</option>
    <option value="444444">444444</option>
    <option value="555555">555555</option>
    </select>
    <select id='dw2'>
    <option value="111111">111111</option>
    <option value="222222">222222</option>
    <option value="333333">333333</option>
    <option value="444444">444444</option>
    <option value="555555">555555</option>
    </select>
    <select id='dw3'>
    <option value="111111">111111</option>
    <option value="222222">222222</option>
    <option value="333333">333333</option>
    <option value="444444">444444</option>
    <option value="555555">555555</option>
    </select>
    <select id='dw4'>
    <option value="111111">111111</option>
    <option value="222222">222222</option>
    <option value="333333">333333</option>
    <option value="444444">444444</option>
    <option value="555555">555555</option>
    </select>
    <select id='dw5'>
    <option value="111111">111111</option>
    <option value="222222">222222</option>
    <option value="333333">333333</option>
    <option value="444444">444444</option>
    <option value="555555">555555</option>
    </select>
    <input type="button" value="Check" onclick="CheckDW()" />
    <script>
    function $(id){return document.getElementById(id);}
    function CheckDW()
    {
      var dw;
      var str = "|";
      for(var i=1;i<5;i++)
      {
        str +=$("dw"+i).value + "|";
      }
      for(var i=1;i<5;i++)
      {
         var val = $(dw"+i).value;
        if(str.IndexOf("|" + val + "|") !=  str.lastIndexOf("|" + val + "|") ) {
           alert('有重复的...');
           break;
        }
      }    
     
      }
    </script>