• ASP.NET jQuery 随笔 从DropDownList获取选择的text和value值


    jQuery来获取DropDownList的Text/Value属性值,代码如下

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Web.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>
        <script src="jquery-1.8.2.min.js" type="text/javascript"></script>
        <link href="Base.css" rel="stylesheet" type="text/css" />
        <style type="text/css">
           
        </style>
        <script type="text/javascript">
            $(document).ready(function () {
                $("#<%=cblHobbies.ClientID%>").bind("change", function () {
                    if ($(this).val() != "") {
                        $("#message").text("Text:" + $(this).find(":selected").text() + "  Value:"+$(this).val());
                    }
     
                });
            });
           
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div style="margin: 100px auto;  400px; height: 200px;">
            <fieldset style=" 400px; height: 150px">
                <p>
                    请选择爱好</p>
                <asp:DropDownList  ID="cblHobbies"  runat="server" >
                 <asp:ListItem Text="--- 请选择 ---" Value="" Selected="True"></asp:ListItem>
                    <asp:ListItem Value="1">音乐</asp:ListItem>
                    <asp:ListItem Value="2">篮球</asp:ListItem>
                    <asp:ListItem Value="3">美剧</asp:ListItem>
                    <asp:ListItem Value="4">电影</asp:ListItem>
                  
                </asp:DropDownList >
            </fieldset>
            <br />
            <div id="message" style="color:blue;"></div>
        </div>
        </form>
    </body>
    </html>

    QQ截图20131212141338

  • 相关阅读:
    SpringBoot使用token简单鉴权
    SpringBoot-dubbo自定义负载均衡实现简单灰度
    SpringBoot基于数据库实现简单的分布式锁
    使用canal增量同步mysql数据库信息到ElasticSearch
    使用go-mysql-elasticsearch同步mysql数据库信息到ElasticSearch
    使用logstash同步mysql数据库信息到ElasticSearch
    extract()函数:用于从一个date或者interval类型中截取到特定的部分
    转://IO的基础概念
    转://MySQL客户端工具的选择
    转://oracle 软件的收费模式
  • 原文地址:https://www.cnblogs.com/jlcoder/p/3471053.html
Copyright © 2020-2023  润新知