码迷,mamicode.com
首页 > 编程语言 > 详细

javascript

时间:2019-04-19 19:43:47      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:生成   substring   结果   重置   换行符   空间   domain   ber   contents   

内置对象

Number

new Number(value);new新对象

Number(value);返回原始数

n.toString(进制数);返回字符串

n.valueOf();返回原始数

Boolean

new Boolean(value);new新对象

Boolean(value);返回原始布尔值

b.toString();返回字符串

b.valueOf();返回原始布尔值

String

new String(value);new新对象

function String(value);返回原始字符串

s.length;返回字符串长度

s.charAt(n);返回索引值处字符

s.indexOf(subs[,start]);返回字符索引值

s.match(r);返回与正则表达式匹配的结果数组

s.replace(r,news);替换与正则表达式匹配的子串

s.search(r);返回与正则表达式匹配的第一个字符位置

s.split(切分处的字符串或正则表达式[,数组最大长度]);字符串切分为数组

s.slice(开始处[,结束处]);提取一个子串

s.substr(开始处[,子串长度]);提取一个子串

s.substring(开始处[,结束处]);提取一个子串

s.toLowerCase();字符串转为小写

s.toUpperCase();字符串转为大写

s.toString();返回字符串

s.valueOf();返回原始字符串

Object

new Object([value]);new新对象

o.constructor;对象的构造函数

o.toString();对象的字符串表示形式

o.valueOf();对象的原始值

Function

new Function(参数,语句);new新对象

f.length;声明函数的形参个数

f.arguments;参数数组

f.prototype;构造函数的原型

f.apply(o,args);将函数作为对象的方法调用

f.bind(o[,arg...]);

f.call(o,arg...);将函数作为对象的方法调用

f.toString();返回字符串

Array

new Array([size/element...]);new新对象

a.length;数组长度

a.indexOf(value[,start]);返回数组元素索引值

a.join([分隔字符]);数组转换为字符串

a.pop();移除最后一个元素

a.push(value...);数组尾部添加元素

a.shift();移除第一个元素

a.unshift(value...);数组头部添加元素

a.concat(value...);数组添加值

a.reverse();倒序

a.slice(start[,end]);返回数组的一部分

a.sort([排序函数]);排序

a.splice(开始处,删除元素个数,插入值);插入、删除、替换数组元素

a.toString();返回字符串

Date

new Date();new新对象

d.get[UTC]FullYear();返回年份值

d.get[UTC]Month();返回月份值

d.get[UTC]Date();返回月份中的日期

d.get[UTC]Day();返回一周中的日期

d.get[UTC]Hours();返回小时值

d.get[UTC]Minutes();返回分钟值

d.get[UTC]Seconds();返回秒钟值

d.getTime();返回毫秒形式

d.set[UTC]FullYear(year[,month,day]);设置年、月、日

d.set[UTC]Month(month[,day]);设置月、日

d.set[UTC]Date(day);设置月份中的日期

d.set[UTC]Hours(hours[,minutes,seconds,millis]);设置时、分、秒

d.set[UTC]Minutes(minutes[,seconds,millis]);设置分、秒

d.set[UTC]Seconds(seconds[,millis]);设置秒

d.setTime(millis);毫秒形式设置

d.toString();返回字符串

d.valueOf();转为毫秒形式

Regexp

new Regexp();new新对象

r.test(s);测试字符串是否匹配正则表达式

r.toString();返回字符串

Global

isNaN(x);是否数值

parseInt(s,radix);字符串转换为整数

parseFloat(s);字符串转换为数字

Math

m.PI;圆周率

m.abs(x);绝对值

m.ceil(x);向上取整

m.floor(x);向下取整

m.round(x);四舍五入

m.random(x);随机数

m.pow(a,b);a的b次方

m.sqrt(x);平方根

DOM

Node类型

node.nodeType节点类型

node.nodeName节点名

node.nodeValue节点值

node.childNodes子节点

node.parentNode父节点

node.previousSibling子节点中上一个同胞节点

node.nextSibling子节点中下一个同胞节点

node.firstChild子节点中第一个节点

node.lastChild子节点中最后一个节点

node.parentNode.appendChild(newNode);子节点末尾添加新节点

node.parentNode.insertBefore(newNode,someoneNode);子节点中的某一个节点前插入新节点

node.parentNode.replaceChild(newNode,someoneNode);子节点中替换某个节点

node.parentNode.removeChild(someoneNode);子节点中移除某个节点

node.cloneNode()

node.normaliza();同一个父节点的子节点中的文本节点合并

Document类型

document.documentElement;表示html元素

document.body;表示body元素

document.title;表示title元素

document.URL;表示页面URl

document.domain;表示页面域名

document.referrer;表示来源页面的URl

document.getElementById("id名");查找id元素

document.getElementsByTagName("标签名");查找标签元素

document.getElemenstByName("属性名");查找属性元素

document.write(s);原样写入

document.writeln(s);末尾加换行符

document.open();

document.close();

document.createElement();创建Element类型节点

document.createTextNode();创建Text类型节点

document.createComment();创建Comment类型节点

document.createDocumentFragment();创建DocumentFragment类型节点

document.createAttribute();创建Attr类型节点

Element类型

element.id;表示元素id属性

element.title;表示元素title属性

element.className;表示元素css类

element.getAttribute("name");获取属性节点

element.setAttribute("name","value");设置属性节点

element.removeAttribute("name");移除属性节点

Text类型

text.splitText(startnum);同一个父节点的子节点中的文本节点分割

Comment类型

comment.splitText(startnum);同一个父节点的子节点中的注释节点分割

DocumentFragment类型

Attr类型

扩展

document.querySelector("css选择器");查找相应的元素

document.querySelectorAll("css选择器");查找相应的所有元素

document.getElementsByClassName("类名");查找类名元素

document.readyState;加载状态complete

element.innerHTML;获取或设置元素内容

element.offsetWidth;元素在水平方向上占用的空间大小(内容加上内边距加上边框加上滚动条)

element.offsetHeight;元素在垂直方向上占用的空间大小(内容加上内边距加上边框加上滚动条)

element.offsetTop;元素的上外边框至包含元素的上内边框的像素距离

element.offsetLeft;元素的左外边框至包含元素的左内边框的像素距离

document.documentElement.clientWidth内容宽度加上内边距宽度

document.body.clientWidth

document.documentElement.clientHeight内容高度加上内边距高度

document.body.clientHeight

BOM

window对象

window.open([surl,starget,sfeatures,sreplace]):打开窗口。返回一个指向新窗口的引用。

window.close():关闭窗口。

window.resizeTo(w,h):调整窗口尺寸到指定值

window.resizeBy(mx,my):增加窗口尺寸,增加量为指定值

window.moveTo(x,y):移动窗口

window.moveBy(mx,my):移动窗口,坐标增加量为指定值

window.innerHeight:浏览器窗口的内部高度

window.innerWidth:浏览器窗口的内部宽度

计时器

window.setTimeout(f,delay):超时调用

window.clearTimeout():取消超时调用

window.setInterval(f,delay):间歇调用

window.clearInterval():取消间歇调用

对话框

window.alert(s):警告框

window.confirm():确认对话框。返回布尔值,点击确定返回true,点击取消返回false

window.prompt():提示框。点击确定返回文本框的值,点击取消返回null

window.print():打印对话框

window.find():查找对话框

navigator对象

navigator.userAgent:用户代理字符串

navigator.plugins:安装插件信息的数组

navigator.onLine:检测设备在线还是离线

screen对象

screen.availWidth:可用的屏幕宽度。以像素计,减去界面特性,比如窗口任务栏。

screen.availHeight:可用的屏幕高度。以像素计,减去界面特性,比如窗口任务栏。

screen.width:屏幕的像素宽度

screen.height:屏幕的像素高度

screen.colorDepth:颜色位数

history对象

history.go():跳转到任意历史记录。若传入整数,正数为前进,负数为后退。若传入字符串,则跳转到历史记录中包含该字符串的第一个位置。

history.back():后退一页

history.forward():前进一页

history.length:历史记录的数量。对于窗口中第一个打开的页面而言,其history.length为0。

history.pushState():历史状态管理。将新的状态信息加入历史状态栈。

history.replaceState:历史状态管理。重写历史状态

location对象

属性

location.href:完整URL,如http://www.bnu.edu.cn:8080/path/to/homepage/index.html?name=‘peter‘&age=‘20‘#contents

location.protocol:协议名,如http:

location.host:服务器名及端口号,如www.bnu.edu.cn:8080

location.hostname:服务器名,如www.bnu.edu.cn

location.port:端口号,如8080

location.pathname:目录和文件名,如/path/to/homepage/index.html

location.search:查询字符串,以问好开头,如?name=‘peter‘&age=‘20‘

location.hash:散列值,即#号后面,如#contents

方法

location.assign():打开指定URL,并在历史记录中生成一条记录。等价于location.href = URL和window.location = URL。

location.replace():打开指定URL,但不生成新的历史记录。

location.reload():重新加载当前页面。默认以最有效的方式加载,可能会请求到缓存。

location.reload(true):重新加载当前页面,强制从服务器重新加载。

EVENT

ele.addEventListener(事件类型,事件处理函数,false);添加事件处理函数

ele.attachEvent(on事件类型,事件处理函数);IE添加事件处理函数

ele.removeEventListener(事件类型,事件处理函数,false);移除事件处理函数

ele.detachEvent(on事件类型,事件处理函数);IE移除事件处理函数

event.preventDefault();取消事件默认行为

event.returnValue=false;

event.stopPropagation();阻止事件冒泡

event.cancelBubble=true;

window.onload;页面加载完成时触发

window.onscroll;滚动条滚动时触发

document.documentElement.scrollTop||document.body.scrollTop;滚动条位置

window.onresize;窗口大小改变时触发

window.onmousewheel;鼠标滚动时触发

event.wheelDelta;==-120向下滚

window.DOMMouseScroll;火狐鼠标滚动时触发

event.detail;=3向下滚

window.onunload;退出页面时触发

document.onreadystatechange;页面加载时触发

document.readyState;加载状态complete

document.ontouchstart;手指触摸屏幕时触发

event.touches[0].pageX;

document.ontouchmove;手指触摸屏幕的位置改变时触发

document.ontouchend;手指移开屏幕时触发

event.changedTouches[0].pageX;

element.onclick;鼠标点击时触发

element.ondblclick;鼠标双击时触发

element.onmouseover;鼠标移动到元素上时触发

element.onmouseout;鼠标移动到另一元素上时触发

element.onmousedown;鼠标按下时触发

element.onmousemove;鼠标移动时触发

element.onmouseup;鼠标松开时触发

element.onkeydown;键盘任意键按下时触发

element.onkeypress;键盘字符键按下时触发

element.onkeyup;键盘任意键弹起时触发

element.onabort;无法加载嵌入内容时触发

element.onerror;无法加载js、图像、嵌入内容、框架时触发

form.elements[];表单元素列表

formelement.disabled;是否被禁用

formelement.value;提交值

formelement.onsubmit;表单提交时触发

formelement.onreset;表单重置时触发

formelement.focus();表单元素获得焦点

formelement.onfocus;表单元素获得焦点时触发

formelement.blur();表单元素移除焦点

formelement.onblur;表单元素移除焦点时触发

formelement.select();文本框获得焦点时选中文本

formelement.onselect;选中文本框文本时触发

formelement.onchange;文本内容变化时触发

ajax

new XMLHttpRequest();创建XMLHttpRequest对象

ajax.open("GET或POST","文件位置",true异步或false同步);设置ajax请求

ajax.send();发送ajax请求

ajax.onreadystatechange;ajax请求时触发

ajax.readyState;4请求完成响应就绪

ajax.status;200找到页面

ajax.responseText;字符串形式的响应数据

JSON

data=JSON.parse(ajax.responseText);

javascript

标签:生成   substring   结果   重置   换行符   空间   domain   ber   contents   

原文地址:https://www.cnblogs.com/murenyangqun/p/10738120.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!