Dom元素的属性常用操作汇总

Posted wensx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Dom元素的属性常用操作汇总相关的知识,希望对你有一定的参考价值。

2月20日汇总:

元素的属性操作:1.$(function(){ $(‘‘#box).attr(‘class‘,‘box‘)});

2.$(‘#box‘).attr({‘title‘:‘标题‘,‘class‘:‘box‘}) 添加多个通过定义对象添加;$("#box").attr("title",function(){ return ‘必须哦‘}) 函数有返回值;

3.$("#box").removeAttr(‘title‘)删除指定元素属性;

4.$(function(){ alert($("#box").css(‘width‘))}) 或$(‘#box‘).css([‘width‘,‘height‘]) 获取到的是一个对象

5.$("#box").css(‘color‘,function(){ return ‘#fff‘});

6. $("#pox").click(function(){ $(this).toggleClass(‘f30 white‘)}) 来回切换 ;

7.$(‘#pox‘).click(function(){ $(this).toggleClass(‘true‘) var count=0; count++%2==0;})

8.$("#pox").innerwidth() $("#pox").innerheight() 指的width/height+padding

9.$("#pox").outerwidth() $("#pox").outerheight() width/height+padding+border

10.$("#pox").outerwidth(true) $("#pox").outerheight(true) width/height+padding+border+margin

以上是关于Dom元素的属性常用操作汇总的主要内容,如果未能解决你的问题,请参考以下文章

js中的DOM操作汇总

Vue 常用属性汇总

DOM操作一些常用的属性总结

DOM相关方法,属性汇总

DOM 常用操作之“查找”

常用的 DOM 方法