• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Jquery操作html常用函数

武飞扬头像
QmagicianRX
帮助1

1. text()

获取元素的文本内容:$("#element").text();

设置元素的文本内容:$("#element").text("New Text");

2. html()

获取元素的 HTML 内容:$("#element").html();

设置元素的 HTML 内容:$("#element").html("<p>New HTML</p>");

3. val()

获取表单元素的值:$("#input").val();

设置表单元素的值:$("#input").val("New Value");

4. attr()

获取元素的属性值:$("#element").attr("attributeName");

设置元素的属性值:$("#element").attr("attributeName", "newValue");

5. removeAttr()

移除元素的指定属性:$("#element").removeAttr("attributeName");

6. addClass()

在元素上添加类:$("#element").addClass("className");

7. removeClass()

从元素上移除类:$("#element").removeClass("className");

8. toggleClass()

在元素上切换类:$("#element").toggleClass("className");

9. hasClass()

检查元素是否具有指定的类:$("#element").hasClass("className");

10. prop() 获取元素的属性值:$("#element").prop("propertyName"); 设置元素的属性值:$("#element").prop("propertyName", "newValue");

11. removeProp() 移除元素的指定属性:$("#element").removeProp("propertyName");

12. wrap() 将元素包裹在指定的 HTML 结构中:$("#element").wrap("<div class='wrapper'></div>");

13. unwrap() 移除元素的父级包装器:$("#element").unwrap();

14. wrapAll() 将一组元素都包裹在一个指定的 HTML 结构中:$(".elements").wrapAll("<div class='wrapper'></div>");

15. wrapInner() 将元素的内容包裹在指定的 HTML 结构中:$("#element").wrapInner("<div class='wrapper'></div>");

16. append() 在元素内部的末尾添加内容:$("#element").append("<p>New Content</p>");

17. prepend() 在元素内部的开头添加内容:$("#element").prepend("<p>New Content</p>");

18. after() 在元素后插入内容:$("#element").after("<p>New Content</p>");

19. before() 在元素前插入内容:$("#element").before("<p>New Content</p>");

20. empty() 移除元素中的所有子元素:$("#element").empty();

21. remove() 移除元素自身以及其所有子元素:$("#element").remove();

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgbhaah
系列文章
更多 icon
同类精品
更多 icon
继续加载