jquery操作dropdownlist值的写法
接着上篇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





