asp.net TreeView中checkBox的单选


如图

代码:

View Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TreeView1.Attributes.Add("onclick ", "OnClientTreeNodeChecked(event) ");

}

}
View Code
//识别不同的浏览器 
function getTargetElement(evt) {
var elem
if (evt.target) {
elem = (evt.target.nodeType == 3) ? evt.target.parentNode : evt.target
}
else {
elem = evt.srcElement
}
return elem
}

var lastC = null;
function OnClientTreeNodeChecked(evt) {
evt = (evt) ? evt : ((window.event) ? window.event : " ");
if (evt == " ") {
return;
}
var obj = getTargetElement(evt);
var hasTreeNode = false;
if (obj.tagName) {
if (obj.tagName == "INPUT" && obj.type == "checkbox") {
if (lastC) lastC.checked = false
lastC = obj;
obj.checked = true;

}
}
}

 

posted on 2012-02-14 10:58  MyBeN  阅读(1729)  评论(0编辑  收藏  举报

导航