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

原文地址:https://www.cnblogs.com/wensx/p/12336183.html

时间: 2024-07-31 19:13:54

Dom元素的属性常用操作汇总的相关文章

jQuery -> 获取/设置/删除DOM元素的属性

jQuery的属性操作很easy,以下以一个a元素来说明属性的获取/设置/删除操作 <body> <a>jquery.com</a> </body> 加入?属性 $('a').attr('href', 'http://www.jquery.com') 加入?多个属性 $('a').attr({'href':'http://www.jquery.com', 'title':'jquery.com'}) 获取属性 $('a').attr('href') clas

jQuery -&gt; 获取/设置/删除DOM元素的属性

Sum square difference Problem 6 The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)2 = 552 = 3025 Hence the difference between the sum of

html标签属性(attribute)和dom元素的属性(property)

attribute和property都有属性之意,但对于attribute和property的区分其实并不难.从对象来说,attribute是html文档上标签属性, 而property则是对应dom元素的自身属性.从操作方法上来看,attribute可以通过dom core规范的接口 getAttribute和setAttribute 进行获取修改,而property可以通过对象访问属性的方式 . 或者 ["  "]来修改获取. 但是对于ie6,7,8(Q)模式下,会与标准w3c浏览

19 01 09 变量 操作元素的属性 和操作元素的方法

变量 JavaScript 是一种弱类型语言,javascript的变量类型由它的值来决定. 定义变量需要用关键字 'var' 变量类型 5种基本数据类型:1.number 数字类型2.string 字符串类型3.boolean 布尔类型 true 或 false4.undefined undefined类型,变量声明未初始化,它的值就是undefined5.null null类型,表示空对象,如果定义的变量将来准备保存对象,可以将变量初始化为null,在页面上获取不到对象,返回的值就是null

元素的属性相关操作element.getAttribute(&#39;xxx&#39;),element.setAttribute(&#39;xxx&#39;,&#39;xxx&#39;),element.removeAttribute(&#39;xxx&#39;)

1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7 <body> 8 <div id="demo" class="one" title="鼠标经过">&

DOM元素选择 属性操作 事件操作 节点操作 创建元素的区别

DOM 获取页面元素 document.getElementById('id'); // id 选择器 document.getElementsByTagName('div'); // 标签选择器 返回伪数组 // html新增 document.getElementsByClassName('box'); // 类名学则器 document.querySelector('#id'): // 返回指定选择器的第一个元素对象,里面写css选择器 document.querySelectorAll(

git - 常用操作汇总

远程仓库相关命令 检出仓库:$ [email protected]:yaoxiabing/saltstack.git查看远程仓库:$ git remote -v添加远程仓库:$ git remote add [name] [url]删除远程仓库:$ git remote rm [name]修改远程仓库:$ git remote set-url --push [name] [newUrl]拉取远程仓库:$ git pull [remoteName] [localBranchName]推送远程仓库:

Scala 学习笔记之集合(9) 集合常用操作汇总

object CollectionDemo10 { def main(args: Array[String]): Unit = { var ls = List[Int](1, 2, 3) //向后增加元素 ls = ls :+ 4 //向前增加元素 ls = 0 +: ls //基本等价 ls = -1 :: ls //向前增加集合 ls = List(-2) ++: ls //基本等价 ls = List(-2) ::: ls //向后增加集合 ls = ls ++ List(5) print

Linux下常用操作汇总

查看linux操作系统位数 (1) 终端输入: file /sbin/init 如 显示: /sbin/init: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped 即是32位的 linux, 如是64位的, 显示的是 64-bit (2) 终端输入: