<!DOCTYPE html>
<html lang="en" ><!--语言声明属性-->
<head>
<meta charset="UTF-8">
<title>shopping list</title>
<style type="text/css">
body{
color:white;
background-color:black;
}
</style>
</head>
<body>
<h1>what to buy</h1>
<p title="a gentle reminder">Don't forget to buy this buff</p>
<ul>
<li>A tin of bean</li>
<li class="sale">cheese</li><!--你可以在所有元素上添加class属性-->
<li class="sale important">Milk</li>
</ul>
<script type="text/javascript">
var paras=document.getElementsByTagName("p");
for(var i=0;i<paras.length;i++)
{
var title_text=paras[i].getAttribute("title");
if(title_text)
{
paras[i].setAttribute("title","brand new title text");
alert(paras[i].getAttribute("title"));
}
}
</script>
</body>
</html>
<html lang="en" ><!--语言声明属性-->
<head>
<meta charset="UTF-8">
<title>shopping list</title>
<style type="text/css">
body{
color:white;
background-color:black;
}
</style>
</head>
<body>
<h1>what to buy</h1>
<p title="a gentle reminder">Don't forget to buy this buff</p>
<ul>
<li>A tin of bean</li>
<li class="sale">cheese</li><!--你可以在所有元素上添加class属性-->
<li class="sale important">Milk</li>
</ul>
<script type="text/javascript">
var paras=document.getElementsByTagName("p");
for(var i=0;i<paras.length;i++)
{
var title_text=paras[i].getAttribute("title");
if(title_text)
{
paras[i].setAttribute("title","brand new title text");
alert(paras[i].getAttribute("title"));
}
}
</script>
</body>
</html>