當(dāng)選擇“女”時,顯示“美女、才女”;當(dāng)選擇“男”時,隱藏 aspx 頁面內(nèi)容:
復(fù)制代碼 代碼如下:
<head runat="server">
<title>用RadioButten(或CheckBox)實(shí)現(xiàn)div的顯示與隱藏</title>
<script type="text/javascript" language="javascript">
function show2() {
if (document.getElementById("Radio2").checked) {
document.getElementById("nvInfo").style.display = "block";
}
else {
document.getElementById("nvInfo").style.display = "none";
}
}
</script>
</head>
<body>
<form runat="server">
<div>
<input type="radio" runat="server" value="11" />男
<input type="radio" runat="server" value="22" />女
<%-- <input type="checkbox" runat="server" value="22" />女--%>
</div>
<div runat="server">
<input type="radio" runat="server" value="11" />美女
<input type="radio" runat="server" value="22" />才女
</div>
</form>
</body>
復(fù)制代碼 代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
this.Radio2.Checked = true;
if (this.Radio2.Checked)
this.nvInfo.Attributes.CssStyle.Add("display", "block"); //從.cs給.aspx中的HTML控件添加CSS樣式屬性
if (this.Radio1.Checked)
this.nvInfo.Attributes.CssStyle.Add("display", "none"); //從.cs給.aspx中的HTML控件添加CSS樣式屬性
}
新聞熱點(diǎn)
疑難解答
圖片精選