1、添加10个div,并添加onclick事件,把对应的添加序号显示出来。

   

<script type="text/javascript">
    var item;
    for(var i=1; i<11; i++){
        item = document.createElement("div");                
        item.innerText = i;
        item.onclick =  (function(i){    
            return function(){
                alert(i);
            }
        })(i);
        document.body.appendChild(item);
    }
</script>

 

相关文章:

  • 2021-08-30
  • 2021-12-06
  • 2021-06-20
  • 2021-07-06
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-29
  • 2022-02-01
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
  • 2022-12-23
  • 2021-09-01
相关资源
相似解决方案