JQuery 添加节点

Mark一段自己写的添加节点的代码

 function reply2(){
         $( "<div class=sec1-div5>"+"<div class=‘sec1-div5-img1‘><img src=‘image/my.jpg‘ width=‘25px‘ height=‘25px‘/></div>" +
                 "<div><p class=‘sec1-p‘><span>我:</span>"+$("#comment").val()+"<br/><span class=‘sec1-span1‘>"
                  +formatDate(new Date())+"</span></p></div></div>"
         ).appendTo("#sec1-div5");
    }

  在附上自己写的一段代码,包含向table中添加行:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>考勤管理系统</title>
    <script src="date10/laydate/laydate.js"></script>
    <meta http-equiv="X-UA-COMPATIBLE" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link rel="stylesheet" href="dist/css/bootstrap.css">
    <link rel="stylesheet" href="date10/laydate/need/laydate.css"/>
    <!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <style>
        body{
            font-family: 微软雅黑;
            background: #EFF0F4;
        }
        @font-face {
            font-family: myfont;
            src: url("font/iconfont.woff");
        }
        .myfont1{
            font-family: "myfont";
            font-size: 15px;

        }
        .title1{
            background: #EFF0F4;
            margin-top: 30px;
            margin-left: 10px;
        }
        .subtitle{
            background: none;
        }
        .title1 ul li a{
            color:#999999;
        }
        .title1 ul li a:hover{
            color: #4CC0C1;
            text-decoration: none;
        }
        .sec1{
            background: white;
            width:98%;
            border-radius: 4px;
            margin-left: 15px;
            margin-top: 20px;
            height:auto;
        }
        .down-arrow,
        .close1
        {
            display: inline-block;
            /*border:1px solid red;*/
            width:30px;
            height:30px;
            background:#E3E4E8 ;
            border-radius: 3px;
            line-height: 30px;
            text-align: center;
            margin-left: 6px;
            -webkit-transition: all linear .3s;
        }
        .down-arrow:hover{
            background: #4CC0C1;
            color:white;
            -webkit-transition: all linear .3s;
        }
        .sec1-head{
            border-bottom: 1px dotted #999999;;
            margin-top: 10px;
            width: 99%;
            margin-left: 10px;
        }
        .sec1-search{
            /*border:1px solid red;*/
            display: inline-block;
        }
        .sec1-search>span{
            font-size: 16px;
            position: relative;
            top:5px;
        }
        .sec1-input{
            width: 30%;
            margin-left: 6px;
            -webkit-transition: all linear .3s;
        }
        .sec1-input:focus{
            width: 34%;
            -webkit-transition: all linear .3s;
            outline: black;
        }
        .sec1-search-icon{
            width:30px;
            height:30px;
            line-height: 30px;
            text-align: center;
            border-radius: 3px;
            background:#E3E4E8 ;
            margin-top: -3px;
            margin-left: 5px;
            -webkit-transition: all linear .3s;
        }
        .sec1-search-icon:hover{
            color:white;
            background: #4CC0C1;
            -webkit-transition: all linear .3s;
        }
        .btn1{
            color:white;
            background:#4CC0C1;
            border:none;
            /*margin-left: 20px;*/
            font-size: 16px;
            -webkit-transition: all linear .3s;
        }
        .btn1 a{
            color:white;
            text-decoration: none;
        }
        .btn2{
            color:white;
            background:#4CC0C1;
            border:none;
            font-size: 13px;
            -webkit-transition: all linear .3s;
        }
        .btn1:hover{
            background:#42aeb2 ;
            color: #fff;
            -webkit-transition: all linear .3s;
        }
        .btn2:hover{
            background:#42aeb2 ;
            color: #fff;
            -webkit-transition: all linear .3s;
        }
        .sec1-Sch{
            margin-top: 40px;
            margin-bottom: 30px;
        }
        .sec1-pageActive{
            background:#4CC0C1!important;
            color:#fff!important;
        }
        .sec1-page{
            /*border:1px solid red;*/
            margin-right: 2px;
        }
        .sec1-select{
            /*border:1px solid red;*/
            text-align: right;
            margin-right: 15px;
            margin-bottom: 10px;
        }
/*----------------手工添加考勤弹窗-------------*/
        .main1{
            background: white;
            /*height:auto;*/
            height:600px;
            margin-top: 60px;
            border-radius: 4px;
        }
        .main1-subtitle{
            background: none;
        }
        .main1-subtitle li a{
            text-decoration: none;
            color:#999999;
        }
        .main1-subtitle li a:hover{
            color:#4CC0C1;
            text-decoration: none;
        }
        .addinfo-title1{
            border-bottom:1px dotted #999999;
        }
        .addinfo_content1{
            margin-top:50px;
        }
        .student_info1{
            border:1px solid #D9D9D9;
            outline: none;
            border-radius:3px;
            height:30px;
            width:450px;
        }
        .student_info1:focus{
            border:1px solid #4CC0C1;
        }
        .input-group{
            margin-top: 30px;
        }
        .addAttend_btn1{
            color:white;
            width:110px;
            background:#4CC0C1;
            border:none;
            margin-left: 40px;
            font-size: 14px;
            margin-top: 30px;
        }
        .addAttend_btn1-1{
            margin-left: 150px;
        }
        .addAttend_btn1:hover{
            background:#42aeb2 ;
            color: #fff;
        }
/*----------学生请假信息录入----------------*/
        .main2{
            background: white;
            /*height:auto;*/
            height:610px;
            margin-top: 60px;
            border-radius: 4px;
        }
        .addinfo-title2{
            border-bottom:1px dotted #999999;
        }
        .addinfo-content2{
            margin-top:50px;
        }
        .student_info2{
            border:1px solid #D9D9D9;
            outline: none;
            border-radius:3px;
            height:30px;
            width:450px;
        }
        .student_info2:focus{
            border:1px solid #4CC0C1;
        }
        .input-group{
            margin-top: 15px;
        }
/*-----------弹窗设置------------*/
        #main1{
            border:1px solid #999999;
            position: absolute;
            z-index: 2;
            margin-left: 7%;
            margin-top: -45%;
            display: none;
        }
        #main2{
            border:1px solid #999999;
            position: absolute;
            z-index: 2;
            margin-left: 7%;
            margin-top: -84%;
            display: none;
        }

    </style>
</head>
<body>
<header class="container-fluid "><!--页头--->
    <div class="row title1">
        <h3 class="col-lg-12 col-xs-12">考勤管理</h3>
        <ul class="breadcrumb subtitle col-lg-12 col-xs-12">
            <li><a href="#">首页</a></li>
            <li><a href="#">考勤管理</a></li>
        </ul>
    </div>
</header>
<!---考勤信息表--->
<section class="sec1 container"><!--考勤信息表,表头--->
 <div class="row container-fluid sec1-head">
    <h4 class="col-lg-6 ">学生出勤明细表</h4>
    <div class="col-lg-6">
        <!--<div class="myfont1  close1 pull-right"></div>-->
        <div class="myfont1  down-arrow pull-right"></div>
    </div>
</div>
 <div class="container sec1-Sch"><!--搜索框--->
    <div class="row">
        <div class="col-lg-4">
            <div class="btn btn1" id="add-Attend"><a href="#">添加考勤信息+</a></div>
        </div>
        <div class=" sec1-search col-lg-8 ">
            <span class="myfont1 sec1-search-icon pull-right"></span>
            <input type="text" placeholder="卡号..." class="form-control sec1-input pull-right"/>
            <input type="text" placeholder="学生姓名..." class="form-control sec1-input pull-right"/>
            <span class="pull-right">搜索:</span>
        </div>
    </div>
</div>
 <div class="container">
    <div class="row">
        <div class="table-responsive">
            <table class="table table-striped table-bordered " id="attendence_table">
                <tr id="table_head">
                    <th>日期</th>
                    <th>星期</th>
                    <th>卡号</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>班级</th>
                    <th>入园刷卡时间</th>
                    <th>出园刷卡时间</th>
                    <th>选择</th>
                </tr>
                <tr>
                    <td>2016.12.12</td>
                    <td>星期一</td>
                    <td>20160101</td>
                    <td>李未央</td>
                    <td>女</td>
                    <td>小一班</td>
                    <td>09:11:12</td>
                    <td>17:30:00</td>
                    <td>
                        <input type="checkbox" class="sec1-checkBox"/>
                    </td>
                </tr>
                <tr>
                    <td>2016.12.12</td>
                    <td>星期一</td>
                    <td>20160102</td>
                    <td>拓跋余</td>
                    <td>男</td>
                    <td>小一班</td>
                    <td>08:20:40</td>
                    <td>18:00:00</td>
                    <td>
                        <input type="checkbox" class="sec1-checkBox"/>
                    </td>
                </tr>
                <tr>
                    <td>2016.12.12</td>
                    <td>星期一</td>
                    <td>20160103</td>
                    <td>拓跋浚</td>
                    <td>男</td>
                    <td>小一班</td>
                    <td>08:50:00</td>
                    <td>17:50:00</td>
                    <td>
                        <input type="checkbox" class="sec1-checkBox"/>
                    </td>
                </tr>
                <tr id="main1_tr">
                    <td>2016.12.12</td>
                    <td>星期一</td>
                    <td>20160108</td>
                    <td>拓跋迪</td>
                    <td>女</td>
                    <td>小二班</td>
                    <td>09:23:40</td>
                    <td>17:00:00</td>
                    <td>
                        <input type="checkbox" class="sec1-checkBox"/>
                    </td>
                </tr>
            </table>
        </div>
        <div class="row sec1-select">
            <!--<a href="#" >全选</a><span>   </span><a href="#" >反全选</a><span>   </span><a href="#" id="Del">删除</a>-->
            <div class="btn btn2" id="selectAll">全选</div>
            <div class="btn btn2" id="Unselect">反全选</div>
            <div class="btn btn2" id="sec1-Del">删除</div>
            <div class="btn btn2">推送邮件</div>
            <div class="btn btn2">导出</div>
        </div>
        <div class="row  sec1-page">
            <nav class="pull-right">
                <ul class="pagination">
                    <li><a href="#">?</a></li>
                    <li><a href="#" class="sec1-pageActive">1</a></li>
                    <li><a href="#">2</a></li>
                    <li><a href="#">3</a></li>
                    <li><a href="#">4</a></li>
                    <li><a href="#">5</a></li>
                    <li><a href="#">?</a></li>
                </ul>
            </nav>
        </div>
    </div>
</div>
</section>
<!-------学生考勤手工添加弹窗------------>
<div class="container main1" id="main1">
    <div class="container-fluid addinfo-title1 row">
        <h4>手工添加考勤信息</h4>
        <ul class="breadcrumb main1-subtitle col-lg-12 col-xs-12">
            <li><a href="#">首页</a></li>
            <li><a href="#">考勤管理</a></li>
            <li><a href="#">学生出勤明细表</a></li>
            <li><a href="#">手工添加学生出勤</a></li>
        </ul>
    </div>
    <div class="container ">
        <div class="row col-md-offset-3 addinfo_content1">
            <div class="input-group">
                <label for="" >打卡日期:</label>
                <input type="text" class="student_info1 laydate-icon " onclick="laydate()" />
            </div>
            <div class="input-group">
                <label for="" >星       期:</label>
                <input type="text" class="student_info1 laydate-icon "  />
            </div>
            <div class="input-group">
                <label for="" >卡       号:</label>
                <input type="text" class="student_info1" />
            </div>
            <div class="input-group">
                <label for="" >姓       名:</label>
                <input type="text" class="student_info1" />
            </div>
            <div class="input-group">
                <label for="" >性       别:</label>
                <input type="text" class="student_info1" />
            </div>
            <div class="input-group">
                <label for="" >班       级:</label>
                <input type="text" class="student_info1" />
            </div>
            <div class="input-group">
                <label for="" >入园时间:</label>
                <input type="text" class="student_info1" />
            </div>
            <div class="input-group">
                <label for="" >离园时间:</label>
                <input type="text" class="student_info1" />
            </div>
            <span class="btn  addAttend_btn1 addAttend_btn1-1" id="main1_Confirm">确认</span>
            <span class="btn addAttend_btn1" id="Cancel_addAttend">取消</span>
        </div>
    </div>
</div>
<!----请假信息------->
<section class="sec1 container"><!--请假管理--->
    <div class="row container-fluid sec1-head">
        <h4 class="col-lg-6 ">学生请假明细表</h4>
        <div class="col-lg-6">
            <!--<div class="myfont1 close1 pull-right"></div>-->
            <div class="myfont1  down-arrow  pull-right"></div>
        </div>
    </div>
    <div class="container sec1-Sch"><!--搜索框--->
        <div class="row">
            <div class="col-lg-4">
                <a href="#" class="btn btn1" id="add_leave">添加请假信息+</a>
            </div>
            <div class=" sec1-search col-lg-8 ">
                <span class="myfont1 sec1-search-icon pull-right"></span>
                <input type="text" placeholder="学号..." class="form-control sec1-input pull-right"/>
                <input type="text" placeholder="学生姓名..." class="form-control sec1-input pull-right"/>
                <span class="pull-right">搜索:</span>
            </div>
        </div>
    </div>
    <div class="container">
        <div class="row">
            <div class="table-responsive">
                <table class="table table-striped table-bordered " id="leave_table">
                    <tr>
                        <th>学号</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>班级</th>
                        <th>请假日期</th>
                        <th>销假日期</th>
                        <th>请教事由</th>
                        <th>备注</th>
                        <th>选择</th>
                    </tr>
                    <tr>
                        <td>20160101</td>
                        <td>李常茹</td>
                        <td>女</td>
                        <td>小一班</td>
                        <td>2016.10.10</td>
                        <td>2016.10.11</td>
                        <td>病假</td>
                        <td>学生妈妈打电话过来请假</td>
                        <td>
                            <input type="checkbox" class="sec2-checkBox"/>
                        </td>
                    </tr>
                    <tr>
                        <td>20160101</td>
                        <td>叱云南</td>
                        <td>男</td>
                        <td>小一班</td>
                        <td>2016.10.10</td>
                        <td>2016.10.11</td>
                        <td>打游戏</td>
                        <td>学生妈妈打电话过来请假</td>
                        <td>
                            <input type="checkbox" class="sec2-checkBox"/>
                        </td>
                    </tr>
                    <tr>
                        <td>20160101</td>
                        <td>叱云柔</td>
                        <td>女</td>
                        <td>小一班</td>
                        <td>2016.09.10</td>
                        <td>2016.10.01</td>
                        <td>病假</td>
                        <td>学生妈妈打电话过来请假</td>
                        <td>
                            <input type="checkbox" class="sec2-checkBox"/>
                        </td>
                    </tr>
                    <tr>
                        <td>20160101</td>
                        <td>李长乐</td>
                        <td>女</td>
                        <td>小一班</td>
                        <td>2016.11.10</td>
                        <td>2016.11.11</td>
                        <td>病假</td>
                        <td>学生妈妈打电话过来请假</td>
                        <td>
                            <input type="checkbox" class="sec2-checkBox"/>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="row sec1-select">
                <!--<a href="#">全选</a><span>   </span><a href="#" >反全选</a><span>   </span><a href="#" >删除</a>-->
                <div class="btn btn2" id="sec2-selectAll">全选</div>
                <div class="btn btn2" id="sec2-Unselect">反全选</div>
                <a href="#" class="btn btn2" id="Edit_addleave">编辑</a>
                <div class="btn btn2" id="sec2-Del">删除</div>
                <div class="btn btn2">推送邮件</div>
                <div class="btn btn2">导出</div>
            </div>
            <div class="row  sec1-page">
                <nav class="pull-right">
                    <ul class="pagination">
                        <li><a href="#">?</a></li>
                        <li><a href="#" class="sec1-pageActive">1</a></li>
                        <li><a href="#">2</a></li>
                        <li><a href="#">3</a></li>
                        <li><a href="#">4</a></li>
                        <li><a href="#">5</a></li>
                        <li><a href="#">?</a></li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</section>
<!-------学生请假手工添加弹窗------------>
<div class="container main2" id="main2">
    <div class="container-fluid addinfo-title2 row">
        <h4>录入学生请假信息</h4>
        <ul class="breadcrumb main1-subtitle col-lg-12 col-xs-12">
            <li><a href="#">首页</a></li>
            <li><a href="#">考勤管理</a></li>
            <li><a href="#">学生请假明细表</a></li>
            <li><a href="#">录入学生请假信息</a></li>
        </ul>
    </div>
    <div class="container ">
        <div class="row col-md-offset-3 addinfo-content2">
            <div class="input-group">
                <label for="" >学       号:</label>
                <input type="text" class="student_info2"/>
            </div>
            <div class="input-group">
                <label for="" >姓       名:</label>
                <input type="text" class="student_info2"/>
            </div>
            <div class="input-group">
                <label for="" >性       别:</label>
                <input type="text" class="student_info2"/>
            </div>
            <div class="input-group">
                <label for="" >班       级:</label>
                <input type="text" class="student_info2"/>
            </div>
            <div class="input-group">
                <label for="" >请假日期:</label>
                <input type="text" class="student_info2 laydate-icon " onclick="laydate()"/>
            </div>
            <div class="input-group">
                <label for="" >销假日期:</label>
                <input type="text" class="student_info2 laydate-icon " onclick="laydate()"/>
            </div>
            <div class="input-group">
                <label for="" >请假事由:</label>
                <textarea  class="student_info2"></textarea>
            </div>
            <div class="input-group">
                <label for="" >备       注:</label>
                <textarea  class="student_info2"></textarea>
            </div>
            <span class="btn  addAttend_btn1 addAttend_btn1-1" id="main2_Confirm">确认</span>
            <span class="btn addAttend_btn1" id="Cancel_addleave">取消</span>
        </div>
    </div>
</div>

<script src="dist/js/jquery-1.11.3.js"></script>
<script src="dist/js/bootstrap.js"></script>
<script>
    $(function(){
        ;!function(){
            laydate({
                elem: ‘#demo‘
            })
        }();
 //考勤中的全选和反全选
        $("#selectAll").click(function(){
          $(".sec1-checkBox").prop("checked",true);
        });

        $("#Unselect").click(function(){
            $(".sec1-checkBox").prop("checked",false)
        });
//考勤管理中的删除
        $("#sec1-Del").click(function () {
            $(".sec1-checkBox").each(function () {
                if ($(this).prop("checked")==true) {
                    $(this).closest("tr").remove();
                }
            });
        });

//请假管理中的全选和反全选
        $("#sec2-selectAll").click(function(){
            $(".sec2-checkBox").prop("checked",true);
        });

        $("#sec2-Unselect").click(function(){
            $(".sec2-checkBox").prop("checked",false)
        });
//请假管理中的删除
        $("#sec2-Del").click(function () {
            $(".sec2-checkBox").each(function () {
                if ($(this).prop("checked")==true) {
                    $(this).closest("tr").remove();
                }
            });
        });
//添加信息中的弹窗
        $("#add-Attend").click(function(){
            $("#main1").css({
                "display":"block"
            })
        });

        $("#add_leave").click(function(){
            $("#main2").css({
                "display":"block"
            })
        });
        $("#Edit_addleave").click(function(){
            $("#main2").css({
                "display":"block"
            })
        });
//弹窗取消
        $("#Cancel_addAttend").click(function(){
            $("#main1").css({
                "display":"none"
            })
        });
        $("#Cancel_addleave").click(function(){
            $("#main2").css({
                "display":"none"
            })
        });
//手工添加打卡信息
        $("#main1_Confirm").click(function(){
            var $tr=$("<tr></tr>");
            $(".addinfo_content1 input:text").each(function (index,domEle) {
                var $td = $("<td></td>");
                $td.append($(domEle).val());
                $td.appendTo($tr);
            });
            var $td=$("<td><input type=‘checkbox‘ class=‘sec1-checkBox‘/></td>");
            $td.appendTo($tr);
            $tr.appendTo("#attendence_table");
            $("#main1").css({
                "display":"none"
            })
        });
//手工录入请假信息
        $("#main2_Confirm").click(function(){
            var $tr=$("<tr></tr>");
//            var $textarea=$("<textarea></textarea>");
            $(".addinfo-content2 input:text").each(function (index,domEle) {
                var $td = $("<td></td>");
                $td.append($(domEle).val());
                $td.appendTo($tr);
            });
            $(".addinfo-content2 textarea").each(function(n,domele){
                var $td = $("<td></td>");
                $td.append($(domele).val());
                $td.appendTo($tr);
            });
            var $td=$("<td><input type=‘checkbox‘ class=‘sec2-checkBox‘/></td>");
            $td.appendTo($tr);
            $tr.appendTo("#leave_table");
            $("#main2").css({
                "display":"none"
            });
            $(window).scrollTop(540);
        });

    })
</script>
</body>
</html>

  下面的代码转载自 http://blog.csdn.net/wo1354691371/article/details/7384829

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery实现添加、移除表格</title>
 </head>
<style>
table{
 margin:auto auto;
background-color:#9FC;}
 td{
  width:80px;}
</style>
<script language="JavaScript" type="text/javascript" src="../../include/jquery.js"></script>
<script language="javascript" type="text/javascript">
   $(document).ready(function (){

    $("#btn1").click(function (){
        //创建tr节点
    var $tr=$("<tr></tr>");
       //遍历获取输入的内容
     $("#info input:text").each(function (index,domEle){
      //添加td节点
       var $td=$("<td></td>");
        //将内容循环添加到创建好的TD中
    $td.append($(domEle).val());
    //将td添加到创建好的TR 中
    $td.appendTo($tr);
      });
      //创建TD--删除
    var $td=$("<td><a href=‘#‘ class=‘del‘>delete</a></td>");
      //将内容循环添加到创建好的TD中
        $td.appendTo($tr);
        $tr.appendTo("#tab");

       //执行删除操作
          $(".del").click(function (){
      //alert("@@@@@@@@@@@@");
      $(this).parent().parent().remove();

     });
     });

    });

</script>
<body>
<form id="info" method="post">
姓名:<input type="text" id="user">
班级:<input type="text" id="greed">
年龄:<input type="text" id="age">
<input type="button" id="btn1" value="添加">
</form>
<br>
<br>
<br>
<table id="tab" border="1">
<tr id="t1">
  <td>姓名</td>
  <td>班级</td>
  <td>年龄</td>
  <td>是否删除</td>
</tr>
</table>
</body>
</html>

  效果是这样的:

时间: 2024-11-21 01:59:31

JQuery 添加节点的相关文章

JS添加节点方法与JQuery添加节点方法的比较及总结

原生JS添加节点方法与JQuery添加节点方法的比较及总结 一.首先构建一个简单布局,来供下边讲解使用 1.HTML部分代码: <div id="div1">div1</div> <div id="div2">div2 <span id="span1">span1</span> <span id="span2">span2</span> <

原生JS添加节点方法与JQuery添加节点方法的比较及总结

一.首先构建一个简单布局,来供下边讲解使用 1.HTML部分代码: <div id="div1">div1</div> <div id="div2">div2 <span id="span1">span1</span> <span id="span2">span2</span> </div> <div id="div

jquery 添加节点的几种方法介绍

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>jQuery插入,复制.替换和删除节点</title> <script type="text/javascript" src="jquery-1.3.2.js"></scri

jquery动态添加节点

<1> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title&

jQuery 复制节点的元素实现添加到购物车功能

描述: 用户点击左边div中的商品,对应商品会自动添加到右面的div中,类似电子商城中的添加到购物车功能. 主要用到了jquery中的复制节点功能,基本原理是首先获取点击的元素,然后将相应信息进行克隆,然后添加到右面的div中. 效果如果: show you code: <!doctype html> <html> <head> <meta charset="utf-8"> <title>jquery test</tit

jQuery的节点添加、删除、替换等操作

//几种添加节点的方法 //$("p").append("<b>你好吗?</b>");//向p元素中追加<b> //$("<b>你好吗?</b>").appendTo("p");//将<b>追加到p元素中 //$("p").prepend("<b>你好吗?</b>");//向p中前置<b

事件冒泡、事件委托、jQuery元素节点操作、滚轮事件与函数节流

一.事件冒泡定义 事件冒泡是指在一个对象触发某类事件(比如单击onclick事件),如果此对象定义了此事件的处理程序,那么此事件就会调用这个处理程序,如果没有定义此事件处理程序或者事件返回true,那么这个事件会向这个对象的父级对象传播,从里到外,甚至它被处理(父级对象所有同类事件都将被激活),或者它到达了对象层级的最顶层,即document对象(有些浏览器是window).. 二.事件冒泡的作用 事件冒泡允许多个操作被集中处理(把事件处理器添加到一个父级元素上,避免把事件处理器添加到多个子级元

js、jquery对节点的操作(增、删)

js对节点的操作方法 一.获取 1.父节点的获取 某节点的parentNode属性值即为该节点的父节点.示例: var parent = document.getElementById("one").parentNode; 2.兄弟节点的获取 nextElementSibling和nextSibling属性配合使用. 某节点的nextElementSibling属性值是该节点后面紧邻的兄弟节点,但是这个有兼容性,在ie9以上版本(包含ie9)和其他浏览器,结果是我们想要的弟节点,在ie

Query节点操作,jQuery插入节点,jQuery删除节点,jQuery Dom操作

一.创建节点 var box = $('<div>节点</div>'); //创建一个节点,或者var box = "<div>节点</div>"; $('body').append(box); //将节点插入到<body>元素内部 二.插入节点 jQuery 提供了好几种个方法来插入节点: 1.内部插入节点方法  方法名 描述 append(content) 向指定元素内部后面插入节点 content append(func