首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

这段JAVASCRIPT写地有错吗? 求救.该如何解决

2012-03-14 
这段JAVASCRIPT写地有错吗? 求救.scriptlanguage javascript !--functionClientValidate(source,arg

这段JAVASCRIPT写地有错吗? 求救.
<script   language= "javascript ">
        <!--
        function   ClientValidate(source,   arguments)
        {
              var       ddl=document.getElementById( "DropDownList1 ");
              for(var       i=0;i <ddl.options.length;i++)
              {  
            if(arguments.Value   ==   ddl.options[i].Value)
            {
                  arguments.IsValid=false;
                  return;
                  }
                }
                arguments.IsValid=true;
      }
      //   -->
        </script>

目的:验证一个TextBox的内容不能和DropDownList里的任何值相等,否则验证失败

但是好象无论输什么都是验证失败.怎样才可以达到目的?

aspx文件如下:
<%@   Page   Language= "C# "   AutoEventWireup= "true "     CodeFile= "Default.aspx.cs "   Inherits= "_Default "   %>

<!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>
                <asp:TextBox   ID= "TextBox1 "   runat= "server "> </asp:TextBox>
                <asp:CustomValidator   ID= "CustomValidator1 "   runat= "server "   ErrorMessage= "ERROR "   ClientValidationFunction= "ClientValidate "  
                ControlToValidate= "TextBox1 "> </asp:CustomValidator>
                <asp:DropDownList   ID= "DropDownList1 "   runat= "server "   Width= "174px ">
                        <asp:ListItem> 001 </asp:ListItem>
                        <asp:ListItem> 002 </asp:ListItem>
                        <asp:ListItem> 003 </asp:ListItem>
                        <asp:ListItem> abc </asp:ListItem>
                </asp:DropDownList>
                <asp:TextBox   ID= "TextBox2 "   runat= "server "> </asp:TextBox> </div>
        </form>


        <script   language= "javascript ">
        <!--
        function   ClientValidate(source,   arguments)
        {
              var       ddl=document.getElementById( "DropDownList1 ");
              for(var       i=0;i <ddl.options.length;i++)
              {  
            if(arguments.Value   ==   ddl.options[i].Value)
            {
                  arguments.IsValid=false;
                  return;
                  }
                }
                arguments.IsValid=true;
      }
      //   -->
        </script>
</body>
</html>



[解决办法]
options[i].Value是谁教你的?

应该是options[i].text
[解决办法]
打字打错了,应该是option[i].value小写
[解决办法]
是小写的value..
[解决办法]
.net 后遗症啊,呵呵,首字母大写。。。。。
[解决办法]
应该小写
[解决办法]
那就改成这样
arguments.Value.toString() == ddl.options[i].value.toString()

再次注意大小写
[解决办法]
好了吧?
[解决办法]
apoclast()
.toString()?后遗症不轻啊

热点排行