日期:2014-05-18  浏览次数:20468 次

JQ怎么取出DropDownList里的全部值和某个值进行比较
我有个文本框当里面的值是DropDownList项里的其中一个,就return true;否则 return false;

------解决方案--------------------
可以用jquery 来实现 很简单,, 

$("select").children("option").each(function(item){
var _optiontext=$(item).val() 或者$(item).text() 看你取text还是val值了
-------------
if($("#_text").val()==optiontext)
{
return true; 
}else{return false;}
});
------解决方案--------------------

HTML code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default11.aspx.cs" Inherits="_20120301_Default11" %>

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

    <script src="../jquery-1.3.2-vsdoc.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function(){
            $("[id$=DropDownList1]").find("option").each(function(){
                if($(this).text() != $("[id$=TextBox1]").val())
                {
                    return false;
                }                
            });           
        });
    </script>
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server">
        <asp:ListItem Text="aaa" Value="aaa"></asp:ListItem>
        <asp:ListItem Text="bbb" Value="bbb"></asp:ListItem>
        <asp:ListItem Text="ccc" Value="ccc"></asp:ListItem>
        <asp:ListItem Text="ddd" Value="ddd"></asp:ListItem>
        </asp:DropDownList>
        <asp:TextBox ID="TextBox1" runat="server"  Text="bbb"></asp:TextBox>
    </div>
    </form>
</body>
</html>

------解决方案--------------------
JScript code

var find=false;
var value=$("#text").val();
$("select").children("option").each(function(){
   if($(this).val()==value){
     find=true;
     return false;
   }
});
if(find){  //找到
}