[.Net码农,JQuery]使用Jquery 改变及使用<asp:DropDownList>

参考Link: http://stackoverflow.com/questions/19243368/get-dropdown-selected-value-using-jquery

参考Link: http://stackoverflow.com/questions/6059240/getting-selected-value-from-net-dropdown-using-jquery


在页面上定义了一个ASP.Net 控件

<div class="rule-single-select" style="width: 100%;">
	<asp:dropdownlist id="ddlDataCategory" name="DataCategoryId" runat="server">
	</asp:dropdownlist>
</div>

产生的页面代码大概是这样的

<div class="rule-single-select single-select" style="width: 100%;">
	<div class="boxwrap">
		<a class="select-tit" href="javascript:;"><span>货币</span><i></i></a>
		<div class="select-items">
			<ul>
				<li class="selected">无类别</li>
				<li>色彩</li>
				<li>消费</li>
				<li>送货</li>
				<li>货币</li>
			</ul>
		</div>
		<i class="arrow"></i>
	</div>
	<select name="ctl00$mainContent$ddlDataCategory" id="mainContent_ddlDataCategory" style="display: none;">
		<option value="1">无类别</option>
		<option value="2">色彩</option>
		<option value="3">消费</option>
		<option value="4">送货</option>
		<option value="5">货币</option>
	</select>
</div>

通过<%=  ***.ClientID   %>获取自动生成的客户端控件ID

$('#<%= ddlDataCategory.ClientID %>')

改变 <asp:DropDownList>需要改变两个内容 :1.显示文本修改

$('#<%= ddlDataCategory.ClientID %>  option:selected').parent().parent().find('.select-tit span').html(
  	$('#<%= ddlDataCategory.ClientID %> option:selected').text());


改变 <asp:DropDownList>需要改变两个内容 :2.内置选项修改

$('#<%= ddlDataCategory.ClientID %>').val(idvalue);

改变 <asp:DropDownList>其余内容

//成功-清空选择
//$('#<%= ddlDataCategory.ClientID %>  option:selected').parent().parent().find('.select-items').find("ul li").removeClass("selected");
//成功-设置选择项:由于index和ID_Value值不一样,就不要用了
//$('#<%= ddlDataCategory.ClientID %>  option:selected').parent().parent().find('.select-items').find("ul li:eq("+index-1+")").addClass("selected");

最后 写上一个这样的JQ涵数 :绅手党你们好

<script>

  function funSetddlDataCategorySelected(idvalue) {
  	//var boxwrapEm=$('#<%= ddlDataCategory.ClientID %>  option:selected').parent().parent().html();
  	$('#<%= ddlDataCategory.ClientID %>').val(idvalue);
  	//成功-清空选择
  	//$('#<%= ddlDataCategory.ClientID %>  option:selected').parent().parent().find('.select-items').find("ul li").removeClass("selected");
  	//成功-设置选择项:由于index和ID_Value值不一样,就不要用了
  	//$('#<%= ddlDataCategory.ClientID %>  option:selected').parent().parent().find('.select-items').find("ul li:eq("+index-1+")").addClass("selected");
  	//成功-改变显示文本
  	$('#<%= ddlDataCategory.ClientID %>  option:selected').parent().parent().find('.select-tit span').html(
  	$('#<%= ddlDataCategory.ClientID %> option:selected').text());
  	//alert($('#<%= ddlDataCategory.ClientID %> option:selected').val());
  	//alert($('#<%= ddlDataCategory.ClientID %> option:selected').text());
  	//alert(boxwrapEm.find('div:first').html());
  } 
</script>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值