您好,欢迎访问一九零五行业门户网

JavaScript知识点总结之 文档对象模型

推荐(免费):javascript(视频)
文档对象模型
document对象常用属性
document.bgcolor:页面背景颜色document.fgcolor:文本的前景颜色document.title:页面标题<body> <h1>对象常用属性</h1> <script type="text/javascript"> document.title=对象常用属性; document.bgcolor=blue; document.fgcolor=white; </script> </body>
document对象查找html元素
document.getelementbyid():根据id查找指定的html页面元素document.getelementsbytagname():所有指定标签名的html页面元素document.getelementsbyname():所有指定name的html页面元素document.getelementsbyclassname():根据类名查找指定的html页面元素<body> <h1 id="top">对象常用属性</h1> <script type="text/javascript"> var x=document.getelementbyid(top); document.write(x.innertext) </script> </body>
document对象改变html
document.getelementbyid().innerhtml=新元素document.getelementbyid().innertext=新内容document.getelementbyid().style.property=新样式document.getelementbyid().attributes=新属性<body> <p id="top"> <h1></h1> </p> <input type="button" value="请输入新内容" onclick="aa()" /> <script type="text/javascript"> function aa(){ var obj=document.getelementbyid(top).innertext=我是新内容 } </script> </body>
dom节点操作
document.getelementbyid().parentnode:当前节点的父节点document.getelementbyid().childnodes:当前节点的所有节点document.getelementbyid().firstchild:当前节点的第一个节点document.getelementbyid().lastchild:当前节点的最后一个节点document.getelementbyid().previoussibling:当前节点的前一个兄弟节点document.getelementbyid().nextsibling:当前节点的后一个兄弟节点document.createelement():添加新节点document.appendchild():移动节点document.removechild():删除节点data对象
var a=new date():当前事件a.getdate():一个月中的某一天a.getday():一周中的每一天a.getfullyear():以四位数返回年份a.gethours():返回小时a.getmilliseconds():返回毫秒a.getminutes():返回分钟a.getmonth():返回月份a.getseconds():分会秒数a.gettime():返回1970.1.1到现在的毫秒数math对象
math. abs(number):返回number的绝对值math.ceil(number):对number向上取整,如math.ceil(67.6)返回值是68math.floor(number):对number向下取整,如math.floor (67.6)返回值是67math.max(number1 ,number2):返回number1与number2中的较大值math.min(number1 ,number2):返回number1与number2中的较小值math.pow(x,y):返回x的y次幂math.random():返回0和1之间的伪随机数,可能为0,但总是小于1,[0,1)math.roundd(number):返回最接近number的整数math.sqrt(number):number的平方根string对象
创建数组方法
var arr=[1,2,3,“happy”];var arr=new array();数组初始元素为0var arr=new array(4);数组初始元素为4var arr=new array(1,2,3);用指定元素去初始化数组创建对象
var 对象名=new 类名(实参1,实参2,实参n)
定义类
function 类名(参数1,参数2...){ this.属性=参数1; this.属性=参数2; ... this.方法名=function(){ //方法体 }}
对象常用语句
with:对某对象属性循环,可简写代码for…in:对某对象所有属性循环,将属性名逐一赋值给临时变量,无需事先知道对象属性个数更多编程相关知识,请访问:编程教学!!
以上就是javascript知识点总结之 文档对象模型的详细内容。
其它类似信息

推荐信息