我的aspx页面上有asp:checkbox
和asp:textbox
,我想知道选中复选框时显示文本框,如果使用javascript取消选中复选框,则隐藏它,我真的很感激任何人谁可以帮助我。
答案 0 :(得分:1)
假设这些在浏览器上呈现为普通复选框和textarea,那么您可以使用其click
事件获得勾选或取消勾选复选框的通知:
$("selector_for_the_checkbox").click(function() {
// ...handle the event here...
});
在事件处理程序中,this
将引用原始复选框元素(不是jQuery包装器)。
要使用jQuery显示隐藏元素,请使用show
;隐藏一个,你使用hide
。您还可以使用toggle
根据当前状态或传入的标记显示或隐藏元素。所以:
$("selector_for_the_checkbox").click(function() {
$("selector_for_the_textarea").toggle(this.checked);
});
非常值得花费一个小时(这就是所需要的)从jQuery API documentation开始阅读。
答案 1 :(得分:1)
你可以使用这段代码
<script type="text/javascript">
function radio_yes(){
if(document.getElementById("c1").checked==true)
document.getElementById("atext").style.visibility="visible";
else
document.getElementById("atext").style.visibility="hidden";}
</script>
<input type="checkbox" id = "c1" name="subscriptions" onclick = "radio_yes();radio_uncheck();" value="CorporateEmails"/>
Corporate Press Release Emails<br />
<input type="text" id="atext">
答案 2 :(得分:0)
试试这个脚本:
<script type="text/javascript">
function toggleTextBox(bEnable, textBoxID) {
document.getElementById(textBoxID).disabled = !bEnable;
}
}
</script>
你的aspx就像:
<asp:CheckBox ID="chkApplied" runat="server" onclick="javascript:toggleTextBox(this.checked, 'txtAmount'); />
<asp:TextBox ID="txtAmount" runat="server"></asp:TextBox>
如果您的客户端ID不同,您可以从服务器端绑定它,如下所示:
chkApplied.Attributes.Add("onclick", "javascript:toggleTextBox(this.checked, '" + txtAmount.ClientID + "');");