zoukankan      html  css  js  c++  java
  • jQuery DOM

    创建节点

    var box = $('<div id="box">节点</div>'); 创建一个节点
    $('body').append(box); //将节点插入到<body>元素内部

    插入节点

    append(content) 向指定元素内部后面插入节点 content
    append(function(index,html){}) 使用匿名函数向指定元素内部后面插入节点
    appendTo(content) 将指定元素移入到指定元素 content 内部后面
    prepend(content) 向指定元素 content 内部的前面插入节点
    prepend(function(index,html){}) 使用匿名函数向指定元素内部的前面插入节点
    prependTo(content) 将指定元素移入到指定元素 content 内部前面

    外部插入节点方法

    after(content) 向指定元素的外部后面插入节点
    content after(function(index,html){}) 使用匿名函数向指定元素的外部后面插入节点
    before(content) 向指定元素的外部前面插入节点 content
    before(function(index,html){}) 使用匿名函数向指定元素的外部前面插入节点
    insertAfter(content) 将指定节点移到指定元素 content 外部的后面
    insertBefore(content) 将指定节点移到指定元素 content 外部的前面

    包裹节点

    wrap(html) 向指定元素包裹一层 html 代码
    wrap(element) 向指定元素包裹一层 DOM 对象节点
    wrap(function(index){}) 使用匿名函数向指定元素包裹一层自定义内容
    unwrap() 移除一层指定元素包裹的内容
    wrapAll(html) 用 html 将所有元素包裹到一起
    wrapAll(element) 用 DOM 对象将所有元素包裹在一起
    wrapInner(html) 向指定元素的子内容包裹一层 html
    wrapInner(element) 向指定元素的子内容包裹一层 DOM 对象节点
    wrapInner(function(index){}) 用匿名函数向指定元素的子内容包裹一层


    节点操作
    $('body').append($('div').clone(true)); 复制一个节点添加到 HTML 中
    $('div').remove(); 直接删除 div 元素
    $('div').detach(); 保留事件行为的删除
    $('div').empty(); 删除掉节点里的内容

    $('div').replaceWith('<span>节点</span>'); 将 div 替换成 span 元素
    $('<span>节点</span>').replaceAll('div'); 同上

  • 相关阅读:
    mongo 索引
    nginx gzip配置
    vim 命令
    Mongo小结
    阿里云ECS服务器连接MongoDB
    python 解析Excel
    Django之数据库--ORM
    sql语句
    关于Django的序列化问题。serializers
    MongoEngine模块
  • 原文地址:https://www.cnblogs.com/xiukang/p/8966525.html
Copyright © 2011-2022 走看看