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.
  • 相关阅读:
    nginx 添加response响应头
    2018年 js 简易控制滚动条滚动的简单方法
    handsontable 常用 配置项 笔记
    使用react-handsontable
    node 常用模块及方法fs,url,http,path
    POST application/json 适用于传递多层的json
    react 子元素修改父元素值的一个偏方,虽然简单,但是不建议用,
    mysql 连接出错 'mysqladmin flush-hosts'
    solr7.3.1定时增量索引
    mysql8修改密码加密方式
  • 原文地址:https://www.cnblogs.com/doit8791/p/3470907.html
Copyright © 2011-2022 走看看