jquery写法转成原生js写法?

JavaScript025

jquery写法转成原生js写法?,第1张

window.onload = function(){

function tree(data){

var str = "<ul class=l_tree>"

for(var i=0i<data.lengthi++){

str+='<li class="l_tree_branch" ><span></span>'+data[i].name

if(data[i].child){

str+=tree(data[i].child)

}

str+="</li>"

}

str += "</ul>"

return str

}

document.querySelector(".lists").innerHTML = tree(data)

var a = document.querySelectorAll(".lists >ul >li")

for(var i=0i<a.lengthi++){

a[i].onclick = function(e){

e.stopPropagation()

console.log(e.target.innerText)

var thatcss = e.target.querySelector("ul").style.visibility

if(thatcss == "hidden"){

e.target.querySelector("ul").style.display = "none"

e.target.querySelector("span").style.background = url(右箭头.png)

}else{

e.target.querySelector("ul").style.display = "block"

e.target.querySelector("span").style.background = url(下箭头.png)

}

}

}

}

onload = function(){

game_start=false

var game_life=0

var game_score=0

var loop_state

var div_down

document.querySelector("#flag").onclick(function()

{

if(game_start==true)

{

game_over()

}

else

{

game_start=true

game_life=3

game_score=0

document.querySelector("#show_life").innerHTML = "生命数:"+game_life

document.querySelector("#show_score").innerHTML="得分数:"+game_score

create_ingot()

loop_state=setInterval(function(){create_ingot()},1500)

div_down=setInterval(function(){go_down()},50)

}