首页 > jquery > jquery操作dropdownlist值的写法

jquery操作dropdownlist值的写法

2009年10月15日 云飞扬 发表评论 阅读评论

接着上篇http://www.ajaxcn.net/archives/368 现在用jquery写,

源码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!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 id="Head1" runat="server">
    <title></title>

    <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        $(document).ready(function() {
            $("#ddlGuo").change(function() {
            alert($("#ddlGuo option:selected").val());
            alert($("#ddlGuo option:selected").text());
                var a = $("#ddlGuo option:selected").val();
                var b = $("#ddlGuo option:selected").text();
                $("#txttext").attr("value", b);
                $("#txtval").attr("value", a);
            });

        });
 
    
    </script>
</head>
<body  >
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="ddlGuo" runat="server"  >
            <asp:ListItem Selected="True" Value="1">C国</asp:ListItem>
            <asp:ListItem Value="2">D国</asp:ListItem>
            <asp:ListItem Value="3">E国</asp:ListItem>
      
        </asp:DropDownList>
        <asp:TextBox ID="txtval" runat="server"></asp:TextBox>
        <asp:TextBox ID="txttext" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>

原创文章转载请注明出处:云飞扬IT的blog

本文链接: http://www.ajaxcn.net/archives/373

分类: jquery 标签:
一键分享到:新浪微博分享  分享到网易微博    转贴到开心网  推荐到豆瓣  分享到QQ空间    RSS订阅
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.