摘要:設定TreeView節點顏色並去除超連結
//移除TreeView主節點之超連結
function addTreeViewNodeSapn() {
var INPUT = document.getElementsByTagName("INPUT");
if (INPUT.length > 0) {
for (var i = 0; i < INPUT.length; i++) {
if (INPUT[i].type == "checkbox") {
var td = INPUT[i].parentNode;
var a = td.childNodes[1];
if (a.href.indexOf("'TreeView1'") != -1) {
if (a.innerText == "全選") { //判斷是否為主節點
//建立新Tag
var span = document.createElement("span");
span.style.color = "black";
var content = document.createTextNode(a.innerText);
span.appendChild(content);
td.removeChild(td.childNodes[1]); //移除超連結
td.appendChild(span);
}
else {
setTreeViewColor(a); //設定顏色
}
}
}
}
}
}
//設定非主節點顏色並移除超連結
function setTreeViewColor(ahref) { //ahref為TreeView的節點
//取得節點所對應之顏色
var KWColor = document.getElementById("HiddKWColor").value;
var KWColorArray = new Array();
for (var i = 0; i < KWColor.split('~').length; i++) {
KWColorArray[i] = new Array(2);
KWColorArray[i][0] = KWColor.split('~')[i].split('-')[0];
KWColorArray[i][1] = "";
for (var j = 0; j < 3; j++) {
KWColorArray[i][1] += KWColor.split('~')[i].split('-')[1].split(',')[j];
}
}
//取得節點的parentNode
var td = ahref.parentNode;
var name = ahref.innerText;
td.removeChild(td.childNodes[1]);
for (var i = 0; i < KWColorArray.length; i++) {
if (KWColorArray[i][0] == name) {
var span = document.createElement("span");
span.style.color ="#"+KWColorArray[i][1];
var content = document.createTextNode(name);
span.appendChild(content);
td.appendChild(span);
}
}
}
TreeView是由Table、checkBox與超連結組成
取得td即可做外觀的改變