我有以下 javascript 函数,我想在选中或取消选中复选框时调用它:
<script language="javascript" type="text/javascript">
function showHideDropDowns() {
var check = document.getElementById('<%= cbShowHideDDLs %>')
if (check.checked) {
document.getElementById('<%=ddlVendor%>').style.visibility = 'visible';
document.getElementById('<%=ddlItem%>').style.visibility = 'visible';
document.getElementById('<%=ddlorigin%>').style.visibility = 'visible';
document.getElementById('<%=tbVendor%>').style.visibility = 'hidden';
document.getElementById('<%=tbItems%>').style.visibility = 'hidden';
document.getElementById('<%=tbOrigin%>').style.visibility = 'hidden';
}
else {
document.getElementById('<%=ddlVendor%>').style.visibility = 'hidden';
document.getElementById('<%=ddlItem%>').style.visibility = 'hidden';
document.getElementById('<%=ddlorigin%>').style.visibility = 'hidden';
document.getElementById('<%=tbVendor%>').style.visibility = 'visible';
document.getElementById('<%=tbItems%>').style.visibility = 'visible';
document.getElementById('<%=tbOrigin%>').style.visibility = 'visible';
}
}
</script>
尝试使用 OnCheckedChanged 或 OnClick 添加和属性无效:
<asp:CheckBox ID="cbShowHideDDLs" runat="server" Text="Show Lists" />
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
cbShowHideDDLs.Attributes.Add("onclick", "showHideDropDowns();");
//cbShowHideDDLs.Attributes.Add("OnCheckedChanged","showHideDropDowns();");
}
}