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.
  • 相关阅读:
    设置了透明以后,会有严重残影
    “真正的工作不是说的天花乱坠”,Torvalds 说, “而是在于细节”(Torvalds 认为成功的项目都是99%的汗水和1%的创新)
    iOS和Android使用MQTT协议实现消息推送和即时通讯(替代XMPP,已经有TMS MQTT)
    avalonjs1.5 入门教程
    Grunt 之 Connect
    性能
    JQUERY省、市、县城市联动选择
    Meteor全栈开发平台
    微型工作流引擎设计
    微型工作流引擎-功能设计
  • 原文地址:https://www.cnblogs.com/doit8791/p/3470907.html
Copyright © 2011-2022 走看看