[英]jquery to select a dropdown list control in asp.net
I am using ASP.net and have a dropdown control. 我正在使用ASP.net并具有下拉菜单控件。
<asp:DropdownList runat="server" ID = "fieldReadOnlyContent" Enabled="false" class = "attribute"><asp:ListItem value = "0">False</asp:ListItem><asp:ListItem value = "1">True</asp:ListItem></asp:DropdownList>
I wanted to adjust the dropdown control via the clientside controls qith jquery. 我想通过客户端控件qith jquery来调整下拉控件。 I get the value which it needs to be set to.
我得到它需要设置的值。
//d[3] will be either true or false.
$("#fieldReadOnlyContent").val(d[3]);
the above attempt didnt seem to set the item to properly enabled. 上述尝试似乎并未将项目设置为正确启用。 HOw would i do this?
我该怎么做?
尝试这个:
$("#<%=fieldReadOnlyContent.ClientID%>").val(d[3]);
The item is not getting set because $("#fieldReadOnlyContent").val(d[3]);
该项目未设置,因为
$("#fieldReadOnlyContent").val(d[3]);
will check for the value
. 将检查
value
。
For your case 对于你的情况
if(d[3]=='false'){
$("#fieldReadOnlyContent").val('0');
}
else
{
$("#fieldReadOnlyContent").val('1');
}
fieldReadOnlyContent
is not necessarily the ID given to the client-side HTML element. fieldReadOnlyContent
不一定是提供给客户端HTML元素的ID。
You can use ClientIDMode="Static"
server-side to control the client-side ID in .net4.0 ( source ), or <%= fieldReadOnlyContent.ClientID %>
to inject the client id directly into the javascript otherwise. 您可以使用
ClientIDMode="Static"
服务器端来控制.net4.0( 源 )中的客户端ID,或者使用<%= fieldReadOnlyContent.ClientID %>
将客户端ID直接注入javascript中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.