JavaScript 最基础四个方法
<style>
body { color:#fff; background:#000; }
p { color:yellow; }
</style>
<body>
<h1>What to buy</h1>
<p title="a gentle reminder">Don't forget to buy this stuff.</p>
<p>Don't forget to buy this stuff222.</p>
<ul id="purchaser">
<li>a tin of beans</li>
<li>chese</li>
<li>milk</li>
<li>orgers</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","fdafsdfsfsdfsdfs");
alert(paras[i].getAttribute("title"));
}
}
var shopping=document.getElementById("purchaser");
alert(shopping.getAttribute("title"));
shopping.setAttribute("title","aaaaaaaaaaaaaaa");
alert(shopping.getAttribute("title"));
</script>
</body>
浙公网安备 33010602011771号