js基础的自定义属性练习

js基础的自定义属性练习:

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>无标题文档</title>

<style>

li { list-style:none; width:114px; height:140px; float:left; margin-right:20px; }

</style>

<script>

window.onload=function(){

 var aLi=document.getElementsByTagName('li');

 for(var i=0;i<aLi.length;i++){

  aLi[i].onOff=true;

  aLi[i].onmouseover=function(){

   if(this.onOff){

    this.style.backgroundColor='blue';

    this.onOff=false;

   }else{

    this.style.backgroundColor='red';

    this.onOff=true;

   }

  };

 }

};

</script>

</head>

<body>

<ul>

 <li></li>

 <li></li>

 <li></li>

</ul>

</body>

</html>

 

posted @ 2017-07-28 20:29  前端站  阅读(165)  评论(0编辑  收藏  举报