单击时更改asp:复选框的文本 [英] Change the Text of an asp:CheckBox when clicked
本文介绍了单击时更改asp:复选框的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在没有回发的情况下更改复选框的文本?
How can I change the Text for a CheckBox without a postback?
<asp:CheckBox ID="CheckBox1" runat="server" Text="Open" />
我想在单击复选框时将文本切换为打开或关闭
I would like to toggle the Text to read "Open" or "Closed" when the CheckBox is clicked on the client.
推荐答案
function changeCheckboxText(checkbox)
{
if (checkbox.checked)
checkbox.nextSibling.innerHTML = 'on text';
else
checkbox.nextSibling.innerHTML = 'off text';
}
称为:
<asp:CheckBox runat="server" ID="chkTest" onclick="changeCheckboxText(this);" />
只是FYI,改变复选框标签的文本通常是不好的做法,因为它倾向于混淆
Just FYI, it's usually bad practice to change the text of the checkbox label because it tends to confuse the user.
这篇关于单击时更改asp:复选框的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文