联系我们
简单又实用的WordPress网站制作教学
当前位置:网站首页 > 网页前端技术 > 正文

ASP.NET jQuery 实例7 通过jQuery来获取DropDownList的Text/Value属性值 - Web前端

作者:98wpeu发布时间:2026-06-26分类:网页前端技术浏览:3


导读:界面代码:复制代码代码如下:<FORMid="form1"runat="server"><divalign="center"><fiel...
界面代码:
复制代码 代码如下:
<FORM id="form1" runat="server">
<div align="center">
<fieldset style="width: 400px; height: 80px;">
<p>
选择颜色:</p>
<asp:DropDownlist ID="ddlcolor" runat="server">
<asp:ListItemtext="--- 请选择 ---" value=""></asp:ListItem>
<asp:ListItem Text="红色" Value="1"></asp:ListItem>
<asp:ListItem Text="黄色" Value="2"></asp:ListItem>
<asp:ListItem Text="蓝色" Value="3"></asp:ListItem>
</asp:DropDownList>
</fIEldset>
</div>
<br />
<div align="center" id="message">
</div>
</Form>

脚本代码:
复制代码 代码如下:
<script src="Scripts/JQuery-1.4.1-vsdoc.JS" type="text/javascript"></script>
<script type="text/JavaScript">
$(document).ready(function () {
// 绑定keyup和change事件
$("#<%=ddlColor.clientID %>").bind("keyup change", function () {
if ($(this).val() != "") {
// 这里需要注意,$(this).text()获取的是整个集合的text属性内容,所以需要再过滤下,把选中的项取出来
$("#message").text("Text: " + $(this).find(":selected").text() + "Value: " + $(this).val());
}
else {
$("#message").text("");
}
});
});
</script>

选择一种颜色显示如下:

标签:实例属性WebTextDropDownListjQuery


网页前端技术排行
最近发表
网站分类
标签列表