zoukankan      html  css  js  c++  java
  • jquery使用总结

    jquery使用总结-常用DOM操作
    (1)查询或设置元素属性操作
    html()   //获取匹配元素集合中的第1个元素
    html(htmlString)  //为匹配集合中的所有元素设置内容
    text()   //返回所有匹配元素集的文本内容组合起来的文本
    text(textString)//设置文本值
    val()   //返回第1个匹配元素的值
    val(value)//设置值
    attr(attributeName)//获取属性值
    attr(attributeName, value)//设置属性值
    (2)插入操作
      将content添加到seletor内部的最后面。
      $(selector).append(content);
      $(selector).append(function(index [,html]){...});
     
      $(content).appendTo(selector);
      将content添加到seletor内部的最前面尾部
      $(selector).prepend(content);
      $(selector).prepend(function(index [,html]){...});
      $(content).prependTo(selector);
     
     
            插入后的节点与原节点是兄弟关系。
      $(selector).after(content);
      $(selector).after(function(index [,html]){...});
      $(content).insertAfter(selector);
     
      $(selector).before(content);
      $(selector).before(function(index [,html]){...});
      $(content).insertBefore(selector);
    (3)删除操作
    $(selector).remove([selector])
    $(selector).detach([selector])
    $(selector).empty()
    remove 方法和 detach 方法的返回值均为被删除的jQuery节点对象,不同的是,前者指保留该对象节点本身,其他绑定的事件及附加的数据等都会被移除。而后者全部保留。empty 方法则是将指定节点的所有子节点删除,本身保留。

    (4)赋值替换操作
    $(selector).clone([true]);带true参数则复制出来的节点具备原节点所绑定的事件处理程序。
    $(content).replaceAll(selector);
    $(selector).repalceWith(content);
    这两种方法在使用时效果完全相同,都是用 content 代替 selector.
  • 相关阅读:
    [HEOI2013]Eden 的新背包问题
    [UOJ#77]A+B Problem
    [CodeForces]786B Legacy
    [LUOGU]P4098[HEOI2013]ALO
    [BZOJ3207]花神的嘲讽计划
    [LUOGU]P2633 Count on a tree
    【东莞市选2007】拦截导弹
    [JZOJ] 3462. 【NOIP2013模拟联考5】休息(rest)
    [BZOJ] 2705: [SDOI2012]Longge的问题
    [BZOJ] 1191: [HNOI2006]超级英雄Hero
  • 原文地址:https://www.cnblogs.com/doit8791/p/3470907.html
Copyright © 2011-2022 走看看