javascript 这段代码运行为什么结果都是undefined?
<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>Document</title><style...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#ul1 li{
background:#FFC;
}
</style>
<script type="text/javascript">
window.onload=function(){
var oul=document.getElementById('ul1');
var oli=oul.getElementsByTagName('li');
for(var i=0;i<oli.length;i++){
oli[i].onclick=function(){
alert(oli[i]);
}
}
}
</script>
<style type="text/css"></style>
</head>
<body>
<ul id="ul1">
<li>sdfsadf</li>
<li>afasfd</li>
<li>asdfasdf</li>
<li>asdfasdf</li>
</ul>
</body>
</html> 展开
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#ul1 li{
background:#FFC;
}
</style>
<script type="text/javascript">
window.onload=function(){
var oul=document.getElementById('ul1');
var oli=oul.getElementsByTagName('li');
for(var i=0;i<oli.length;i++){
oli[i].onclick=function(){
alert(oli[i]);
}
}
}
</script>
<style type="text/css"></style>
</head>
<body>
<ul id="ul1">
<li>sdfsadf</li>
<li>afasfd</li>
<li>asdfasdf</li>
<li>asdfasdf</li>
</ul>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询