您的位置:首页 > 编程语言 > ASP

ASP.NET - Code Samples - Disable CheckboxList Items

2007-01-16 09:54 337 查看
//Add This Code To the HTML directly
// checkboxlistID = id of the checkboxlist
// chkarray = array of indexes to set enable or disable
// disable = true to disable
<script language=javascript>
function disableListItems(checkBoxListId, chkArray, disable)
{
// Get the checkboxlist object.
objCtrl = document.getElementById(checkBoxListId);

// Does the checkboxlist not exist?
if(objCtrl == null)
{ return;
}

var i = 0;

// iterate through listitems that need to be enabled or disabled
for(i = 0; i<chkArray.length; i++)
{
objItem = document.getElementById(checkBoxListId + '_' + chkArray[i]);

if(objItem == null)
{
continue;
}

// Disable/Enable the checkbox.
objItem.disabled = disable;
// Should the checkbox be disabled?
objItem.checked = false;

}
}
</script>

'Add Code to the page load event (this demonstrates disabling the 2nd and 3rd items)

'Disable on intial Page Load
If Not Me.IsStartupScriptRegistered("doit") Then
Me.RegisterStartupScript("doit", "<script language=""javascript"">disableListItems('checkBoxList1',new Array(1,2),true);</script>")
End if

'Disable on checkboxlist click
CheckBoxList1.Attributes.Add("onclick", _
"disableListItems('checkBoxList1',new Array(1,2),true)")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: