如何使用javascript在asp.net中设置标签文本 [英] how to set text of label in asp.net using javascript
问题描述
i有拖曳列表的拖拽列表,当我选择其中一个我想要更改可能标签的文本我已将此指令添加到我的功能javascript并且我有这个
无法修改Controls集合,因为控件包含代码块(也就是说<%...%>)
这是我的代码
功能TChanged(){
if (document.getElementById( cmb_choi)。 value == HeureP){
document.getElementById(' <%= lblnbr.ClientID%> ;')。 value = ' Nbr HEURE'跨度>;
}
else if (document.getElementById( cmb_choi)。 value == JourP){
document.getElementById(' <%= lblnbr.ClientID%>')。text = ' Nbr Jour';
}
}
< pre lang =xml> < asp:DropDownList ID = cmb_choi CssClass = drp runat = server AppendDataBoundItems = 真 onchange = TChanged() >
< asp:ListItem 文字 = - Période - 值 = Période > < / asp:ListItem >
< asp:ListItem 文字 = Jour 值 = JourP > < ; / asp:ListItem >
< asp:ListItem 文字 = heur 值 = MoisP > < / asp:ListItem >
< / asp:DropDownList >
< asp:标签 ID = lblnbr runat = server 文字 = 标签 > < / asp:Label >
尝试使用下面的脚本,这将在下拉控件的选择更改时更新标签值。
function TChanged()
{
var control = document.getElementById('<%= cmb_choi.ClientID%>');
var selectedvalue = control.options [control.selectedIndex] .value;
if(selectedvalue ==HeureP)
{
document.getElementById('<%= lblnbr.ClientID%>')。innerHTML ='Nbr heure' ;
}
else if(selectedvalue ==JourP)
{
document.getElementById('<%= lblnbr.ClientID%>')。innerHTML ='Nbr怨妇;
}
}
您好,
试试这个
< asp:下拉列表 id = cmb_choi cssclass = drp runat = server appenddatabounditems = True < span class =code-attribute> onchange = TChanged();返回false; >
< asp:listitem text = - Période - value = Période > < / asp:listitem >
< asp:listitem text = < span class =code-keyword> Jour value = JourP > < / asp:listitem >
< asp:listitem text = < span class =code-keyword> heur value = MoisP > < / asp:listitem >
< / asp:dropdownlist >
< asp:label id = lblnbr runat = server text < span class =code-keyword> = 标签 > < / asp:label >
请参考此链接http://stackoverflow.com/questions/6986504/how-to-set-text-to-label-with-jquery
如果我错过了解问题,请告诉我。
hi,
i have dropdownlist with tow element when i chose one of them i want to change text of may label i have add this instruction to my function javascript and i have this
The Controls collection can not be modified because the control contains code blocks (that is to say <% ...% > )
and this is my code
function TChanged() {
if (document.getElementById("cmb_choi").value == "HeureP") {
document.getElementById('<%=lblnbr.ClientID%>').value = 'Nbr heure';
}
else if (document.getElementById("cmb_choi").value == "JourP") {
document.getElementById('<%=lblnbr.ClientID%>').text = 'Nbr Jour';
}
}
<asp:DropDownList ID="cmb_choi" CssClass="drp" runat="server" AppendDataBoundItems="True" onchange="TChanged()">
<asp:ListItem Text="--Période--" Value="Période"></asp:ListItem>
<asp:ListItem Text="Jour" Value="JourP"></asp:ListItem>
<asp:ListItem Text="heur" Value="MoisP"></asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lblnbr" runat="server" Text="Label"></asp:Label>
Hi,
Try with below script, this will update label value on selection changes of dropdown control.
function TChanged() { var control = document.getElementById('<%= cmb_choi.ClientID %>'); var selectedvalue = control.options[control.selectedIndex].value; if (selectedvalue == "HeureP") { document.getElementById('<%=lblnbr.ClientID%>').innerHTML = 'Nbr heure'; } else if (selectedvalue == "JourP") { document.getElementById('<%=lblnbr.ClientID%>').innerHTML = 'Nbr Jour'; } }
Hi,
Try this
<asp:dropdownlist id="cmb_choi" cssclass="drp" runat="server" appenddatabounditems="True" onchange="TChanged(); return false;" > <asp:listitem text="--Période--" value="Période"></asp:listitem> <asp:listitem text="Jour" value="JourP"></asp:listitem> <asp:listitem text="heur" value="MoisP"></asp:listitem> </asp:dropdownlist> <asp:label id="lblnbr" runat="server" text="Label" ></asp:label>
Please refer this link http://stackoverflow.com/questions/6986504/how-to-set-text-to-label-with-jquery
Let me know if I miss understood the question.
这篇关于如何使用javascript在asp.net中设置标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!