您的位置:首页 > Web前端 > JavaScript

js常用方法和事件

2015-12-24 12:05 483 查看
<span style="font-size:24px;">//BOM DOM
//window 浏览器对象模型,它的parseInt等都是,navigator是分页浏览器本身信息
//使用window.location获取一些URL信息对象,所带的对象属性如href.hash.host.hostname.pathname.port.protocol.search等,刷新reload() assign() replace
//window.reload()     window.location.href=window.location.href;  location=location
//window.history
//screen.width  screen.availWidth   screen.height  screen.availHeight
//window.open() close()
//window.moveTo() window.resizeTo() window.moveBy(100,100)这些都只有用window.open打开的时候能控制
//window.alert() prompt() confirm()
//window.setTimeout() window.setInteval()
//var id=window.setTimeout(boo,2000)
//var id=window.clearInterval(boo,2000)
//var win=window.open('http://www.baidu.com','packet','windth=300,height=300,resizable=yes');
//win.moveTo(500,100);
//window.document是一个BOM对象,表示的是当前所载入的文档,它的方法和属性同事属于DOM对象所涵盖的范围
//window.document表示文档对象模型
//document.documentElement.nodeName tagName
//document.documentElement.hasChildNodes()
//document.documentElement.childNodes[1]指的是body元素
//访问元素属性
//bd.childNodes[1].hasAttribute()
//bd.childNodes[1].attributes.length
//bd.childNodes[1].attributes[0].nodeVaue// nodeName
//bd.childNodes[1].attributes['class'].nodeValue
//bd.childNodes[1].getAttribute('class')
//获取标签中的内容textContent,好多都不支持  innerText innerHtml
//通过childNodes parentNode nodeName nodeValue attributes这些集合可以操作树了
//但是空白处也会成为一个节点,所以有了getElementsByTagName() getElementsByName ()
//getElementById()
//如:document.getElementsByTagName('p').length
//可以使用索引来访问,也可以使用item/ document.getElementsByTagName('p').item(0)
//一些方法nextSibling previousSibling firstChild lastChild
//dom节点修改 var my=document.getElementById('closer');my.innerHTML='';
//修改样式
//my.style.border="1px solid red";
//my.style.fontWeight='bold'; 对于font-weight margin-left都用fontWeight marginLeft
//使用var map=document.createElement("p");创建节点//createTextNode
//myp.innerHTML='yetl;sdjflsj';
//myp.style.border="1px solid red";
//使用appendChild()方法来追加
//cloneNode()和insertBefore()一个是复制节点一个是将新节点添加到指定节点的末端
//移除节点用removeChild()
//var myp=document.getElementByTagName('p')[1];
//var removed=document.body.removeChild(myp);
//只适用于HTML的DOM对象
//document.images document.applets document.links  document.anchors document.forms
//document.write() document.cookie document.title doucument.title document.referrer
//document.domain
//事件 addEventListener()
//var mypara=document.getElementById('closer');
//mypara.addEventListener('click',function(e){});第三个参数false不使用冒泡,true使用冒泡
//e.stopPropagation()阻止事件传播,e.preventDefault()阻止默认行为
//IE中attachEvent()
//对应的removeEventListener() detachEvent()
//在IE中没有事件的target,用srcElement
//onAbort onBlur onChange onClick
//onDblCLick onDragDrop onError onFocus onKeyDown onKeyPress onKeyUp on Load onMouseDown onMouseMove onMouseOue onMouseOver   onDrapDrop onError onFocus onSelect onSubmit onUnload</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: