zoukankan      html  css  js  c++  java
  • 增加删除div

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    </head>

    <body>
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
    .div_list{
    display: block;
    100px;
    height: 100px;
    border: 1px solid #000;
    }
    .btn_list{
    position: absolute;
    left: 120px;
    }

    </style>
    <script type="text/javascript">
    window.onload = function(){


    function div_elem(i){
    return '<div id="d'+i+'" class="div_list"><input type="button" value="删除'+i+'" id="input'+i+'" class="btn_list"></div>';
    }

    function add_div(){

    var odiv_add = document.getElementById('div_add');
    var obtn1 = document.getElementById('btn1');
    var count1 = 0;


    obtn1.onclick = function(){
    var div_data = '';
    count1++;
    if (count1<=6) {
    for(var i = 0; i<count1; i++){
    div_data += div_elem(i);
    }
    }else{
    alert('不能再增加了');
    return;
    }
    odiv_add.innerHTML = div_data;
    function btn_delete(){
    var obtn_list = document.getElementsByClassName('btn_list');

    for(var j = 0; j<obtn_list.length;j++){
    (function(j){
    obtn_list[j].onclick = function(){
    count1--;
    odiv_add.removeChild(odiv_add.childNodes[j]);
    btn_delete();
    }
    })(j);
    }
    }

    btn_delete()
    }

    }

    add_div();

    }

    </script>
    </head>
    <body>
    <div id="div_add"></div>
    <input type="button" id="btn1" value="增加" />
    </body>
    </html>
    </body>
    </html>

  • 相关阅读:
    Quartus II -----破解
    博客诞生
    OpenMPI 学习笔记(一)并行计算机和分布式计算
    信息安全(1):安全策略
    认证
    SSL/TLS 和Https
    IPSec 网络协议安全
    C# 快速高效率复制对象另一种方式 表达式树
    C语言学习指针和数组2
    C语言学习二维数组
  • 原文地址:https://www.cnblogs.com/gyc51/p/8064013.html
Copyright © 2011-2022 走看看