<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<p id="intro">我的课程</p>
<ul>
<li title="JS">JavaScript</li>
<li title="JQ">JQuery</li>
<li title="">HTML/CSS</li>
<li title="JAVA">JAVA</li>
<li title="">PHP</li>
</ul>
<h1>以下为li列表title的值,当title为空时,新设置值为"WEB前端技术":</h1>
<script type="text/javascript">
var Lists=document.getElementsByTagName("li");
for (var i=0; i<Lists.length;i++)
{
var text = Lists[i].getAttibute("title");
document.write(text +"<br>");
if(text=="")
{
List[i].setAttribute("title","WEB前端技术")
document.write(Lists[i].getAttribute("title"+"<br>");
}
}
document.write("hello world!");
</script>
</body>
</html>
一共四处错误:
第一处 var text = Lists[i].getAttibute("title"); // setAttritube写错了!
第二处 List[i].setAttribute("title","WEB前端技术"); // Lists[i]中你写了List!
第三处 List[i].setAttribute("title","WEB前端技术") //此处结尾没有加分号“;”!
地四处 document.write(Lists[i].getAttribute("title"+"<br>"); //此处输出最后少半个括弧!
List[i].setAttribute("title","WEB前端技术") 改为 Lists[i].setAttribute("title","WEB前端技术");
var text = Lists[i].getAttibute("title");改为 var text = Lists[i].getAttribute("title");
是setAttribute,少打了一个r;
List[i].setAttribute("title","WEB前端技术");改为Lists[i].setAttribute("title","WEB前端技术");
是Lists,打少了一个s