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>
相关文章推荐
- {"0":"192.168.1.100","1":"192.168.1.101"} 是Map
- js,将日期时分秒等格式化和转化
- JSTL动态加载单选框--【ssnc】
- html5载入JS引用
- javascript时间戳和日期字符串相互转换
- mvc使用JsonResult返回Json数据
- js-图标控件
- Jsoup 网页抓取数据之获取汽车时刻表 实例解析
- json 转换为 map、对象
- JavaScript 前端编程使用小技巧
- js对表单设置了readonly和disabled后的区别
- Ajax跨域、Json跨域、Socket跨域和Canvas跨域等同源策略限制的解决方法
- JavaScript的性能优化:加载和执行
- js获取当前url主机名和端口号
- 高性能Javascript:脚本的无阻塞加载策略
- 浏览器内核及JS引擎各有什么功能
- 探真无阻塞加载javascript脚本技术,我们会发现很多意想不到的秘密
- JS 字符串操作函数 往指定位置插入字符 删除指定位置字符 替换指定位置字符
- 让你分分钟学会javascript闭包
- js 无缝滚动