请问这个代码的问题在哪里,好像是作用域的问题,具体的不明白
window.onload = seek;
function preOrder(node){
array.push(node);
node.firstElementChild?(preOrder(node.firstElementChild)):null;
node.lastElementChild?(preOrder(node.lastElementChild)):null;
}
function inOrder(node){
node.firstElementChild?(preOrder(node.firstElementChild)):null;
array.push(node);
node.lastElementChild?(preOrder(node.lastElementChild)):null;
}
function postOrder(node){
node.firstElementChild?(preOrder(node.firstElementChild)):null;
node.lastElementChild?(preOrder(node.lastElementChild)):null;
array.push(node);
}
function seek(){
var root = document.getElementById("root");
var array = [];
var pre = document.getElementById("preOrder");
var mid = document.getElementById("inOrder");
var post = document.getElementById("postOrder");
pre.onclick = function(){
preOrder(root);
}
mid.onclick = function(){
inOrder(root);
}
post.onclick = function(){
postOrder(root);
}
}
function preOrder(node){
array.push(node);
node.firstElementChild?(preOrder(node.firstElementChild)):null;
node.lastElementChild?(preOrder(node.lastElementChild)):null;
}
function inOrder(node){
node.firstElementChild?(preOrder(node.firstElementChild)):null;
array.push(node);
node.lastElementChild?(preOrder(node.lastElementChild)):null;
}
function postOrder(node){
node.firstElementChild?(preOrder(node.firstElementChild)):null;
node.lastElementChild?(preOrder(node.lastElementChild)):null;
array.push(node);
}
function seek(){
var root = document.getElementById("root");
var array = [];
var pre = document.getElementById("preOrder");
var mid = document.getElementById("inOrder");
var post = document.getElementById("postOrder");
pre.onclick = function(){
preOrder(root);
}
mid.onclick = function(){
inOrder(root);
}
post.onclick = function(){
postOrder(root);
}
}
...全文


