js操作VS控件TreeView
<script language="javascript" type="text/javascript">
//TreeView onclick 触发事件
function client_OnTreeNodeChecked(event) {
//得到当前所 Click 的对象
var objNode;
if (!public_IsObjectNull(event.srcElement)) {
//IE
objNode = event.srcElement;
} else {
//FF
objNode = event.target;
}
//判断是否 Click 的 CheckBox
if (!public_IsCheckBox(objNode))
return;
var objCheckBox = objNode;
//根据CheckBox状态进行相应处理
if (objCheckBox.checked == true) {
var objID = objNode.getAttribute("ID");
var tmpIndex = objID.replace("MainContent_treen", ""); //MainContent_treen2CheckBox
var index = tmpIndex.replace("CheckBox", "");
objID = "MainContent_treet" + index;
$("#<%=lblParentName.ClientID %>").text($("#" + objID).text());
var action = '<%=_action %>';
if (action != "")
$("#<%=txtCategoryName.ClientID %>").val($("#" + objID).text());
public_SetAllUnChecked(objCheckBox);
} else {
var objID = objNode.getAttribute("ID");
var tmpIndex = objID.replace("MainContent_treen", ""); //MainContent_treen2CheckBox
var index = tmpIndex.replace("CheckBox", "");
objID = "MainContent_treet" + index;
$("#<%=lblParentName.ClientID %>").text("Root");
}
}
function public_SetAllUnChecked(objCheckBox) {
$("[id^=MainContent_treen]").each(function (i) {
$(this).parent().removeClass("checked");
$(this).attr("checked", false);
$(objCheckBox).attr("checked", true);
$(objCheckBox).parent().addClass("checked");
});
}
//判断对象是否为空
function public_IsObjectNull(element) {
if (element == null || element == "undefined")
return true;
else
return false;
}
//判断对象是否为 CheckBox
function public_IsCheckBox(element) {
if (public_IsObjectNull(element))
return false;
if (element.tagName != "INPUT" || element.type != "checkbox")
return false;
else
return true;
}
</script>