一、js组成
1. ECMAScript 标准规范 (actionScript也遵循此规范,是js的核心) 几乎完全兼容,因为功能简单
2. DOM document object model 文档对象模型 大部分兼容,不兼容还可以写兼容 提供操作结构的接口
3. BOM browser ojdect model 浏览器对象模型,即window对象 基本不兼容,且无法写兼容 提供操作浏览器的方法和接口 window.navigator.userAgent
二、DOM
标签、元素、节点
1. 获取子节点:children----只包含第一层 childrenNotes 子级,不建议用
获取父节点:parentNode
例子:隐藏li
var aA=document.getElementsByTagName('a');
for(var i=0; i<aA.length; i++){
aA[i].onclick=function(){
this.parentNode.style.display='none';
}
}
点击它,删除它的父级。当父级不定的时候:
oA.onclick=function(){
this.parentNode.parentNode.removeChild(this.parentNode);
}
2. 获取首尾子节点
(1)firstChild------只兼容ie8以下,chrome认识,但是是一个文本节点
firstElementChild----兼容高级浏览器,IE678 undefined;可以用来作为判断浏览器的条件
(2)lastChild---只兼容ie8以下
lastElementChild---兼容高级浏览器
if(oUl.firstElementChild){
oUl.firstElementChild.style.background='red';
}else{
oUl.firstChild.style.background='red';
}
oUl.children[oUl.children.length-1].style.background='red';
3. 或
只要第一个为真,则整个条件为真
所以,var oFirst=oUl.firstElementChild || oUl.firstChild;
oFirst.style.background='red';
4. 兄弟节点
(1)获取下一个兄弟节点:nextSibling---只兼容ie8- nextElementSibling
var oNext=oLi.nextElementSibling || oLi.nextSibling;
oNext.style.background='red';
(2)获取上一个兄弟节点:previousSibling---只兼容ie8- previousElementSibling
var oPre=oLi.previousElementSibling || oLi.previousSibling;
5. 与 &&
false&&alert(1); 不会弹1 如果第一个为假,就不用看后面,整个式子肯定为假;如果第一个为真,才需要看看后面的值
小结:只有第一个为真时,后面才执行。 oDiv&&(oDiv.style.background='red');
if(条件){语句}==条件&&语句
或:只有第一个为假的时候,后面才执行
6. 创建、插入、删除元素
(1)creatElement(标签名);
(2)appendChild(元素);----插入到最后
插入到某个元素之前:insertBefore(新建元素, 某个元素);
insertBefore特性 bug 如果第二个参数为空 则默认插入
如果用到length 则要注意appendChild之前和之后的不同,如:
在appendChild之前:oBtn.onclick=function(){var oLi=document.createElement('li');oLi.style.background='red';oLi.innerHTML=oUl.children.length+1;oUl.appendChild(oLi);}在appendChild之前:oBtn.onclick=function(){var oLi=document.createElement('li');oLi.style.fontSize='30px';oUl.appendChild(oLi);oLi.innerHTML=oUl.children;}
(3)removeChild(要删除的东西);
例子—模拟留言板:
window.onload=function(){
var oTxt1=document.getElementById('txt1');
var oTxt2=document.getElementById('txt2');
var oBtn=document.getElementById('btn1');
var oUl=document.getElementsByTagName('ul')[0];
oBtn.onclick=function(){
var oNewLi=document.createElement('li');
var oNewH=document.createElement('h2');
var oNewP=document.createElement('p');
oNewH.innerHTML=oTxt1.value;
oNewP.innerHTML=oTxt2.value;
oNewLi.appendChild(oNewH);
oNewLi.appendChild(oNewP);
if(oUl.children[0]){
oUl.insertBefore(oNewLi,oUl.children[0]);
}else{
oUl.appendChild(oNewLi);
}
oTxt1.value='';
oTxt2.value='';
}
}
7. 几对关键词
(1)onscroll:滚动条滚动事件
(2)scrollTop:获取滚动的距离
document.documentElementScrollTop----只支持ie和ff,不支持Chrome
document.body.scrollTop----只支持Chrome
兼容写法:var scrollTop=document.documentElement.scrollTop || document.body.scrollTop;(也可以反着写)
scrollLeft:用法用scrollTop一样
(3)clientWidth /clientHeight:获取可视区的宽度/高度
完全兼容:document.documentElement.clientWidth/clientHeight
(4)offsetWidth / offsetHeight:获取元素的盒子模型的高度(width、padding、border)。display:none就获取不到。块级元素的宽高,默认是父元素的100%
oDiv.style.top=scrollTop+clientHeight-offsetHeight;
(5)offsetLeft / offsetTop:到有定位的父级的距离
(6)onresize:当窗口大小改变的时候触发
8. document.write:如果在页面加载之后,执行document.write(),就会清空其他所有内容;
9. 关于window
(1) open:打开一个页面,有返回值 新的窗口的对象
window.open(网址,名字(类似a的target))
oBtn.onclick=function(){
window.open("close.html","_blank");
};
(2)window.close();----关闭一个页面。不兼容ff,不能关闭非脚本打开的窗口,只能关闭由js打开的页面
oBtn.onclick=function(){
window.close();
};
(3)window.location 获取浏览器当前访问的地址
(4)http://www.a.com/app/a.html?a=12#1
protocal 协议 http:
host 域名 www.a.com
pathname 路径名 /app/a.html
search 数据 ?a=12
hash 锚 #1
(5)history 历史记录
.go(-1) 后退
.go(1) 前进
(6)navigator 浏览器信息
(7)userAgent
(8)language 语言
(9)platform 操作系统
(10)screen 屏幕信息--分辨率 screen.width screen.height
(11)colorDepth 色彩 window.screen.colorDepth
10. 各种弹出框
(1)alert();------警告框,弹一下就完事
(2)confirm;----确认框,返回布尔值
var result=confirm ('你确认是帅哥吗?');
alert(result);
(3)prompt-----输入框,返回的是输入的字符串,如果取消,返回null
var str=prompt('what is your name?','请在这里输入你的名字。'); alert(str);
相关推荐
谷歌浏览器平滑滚动扩展 ... 特性 - Picasa-like smooth scrolling- Mouse wheel, middle mouse and keyboard support- Arrow keys, PgUp/PgDown, Spacebar, Home/End- Customizable step sizes, frames per second ...
smoothScroll.js 是极小的,符合标准的平滑滚动脚本,无依赖,支持 Firefox, Chrome, IE10, Opera 和 Safari。使用:[removed][removed]示例:var smoothScroll = require('smoothscroll'); var exampleBtn = ...
better-scroll.js
第七讲.(下)Jquery.Mobile插件.scroll.js.下拉更新插件
滚动betterscroll.js下载,滚动betterscroll.js下载,滚动betterscroll.js下载,滚动betterscroll.js下载,滚动betterscroll.js下载,滚动betterscroll.js下载,滚动betterscroll.js下载,滚动betterscroll.js下载,...
pagescroll.js 安装: npm i @woobble/pagescroll.js 用法: import pagescroll from '@woobble/pagescroll.js' // Create instance const pScroll = pagescroll ( { tags : [ "tag1" , "tag2" , ] , ...
jquery文字图片滚动插件scroll.js下载地址
jquery需要的所有js文件 /*! * jQuery UI 1.8.18 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. * http://jquery.org/license * ...
人工智能-项目实践-新闻...(文本分类)朴素贝叶斯实现的新闻分类 新闻共分7类,新闻信息在此采集: 1 财经 http://finance.qq.com/l/201108/scroll_17.htm 2 科技 http://tech.qq.com/l/201512/scroll_02.htm 3 汽车 ...
better-scroll 是一款重点解决移动端(已支持 PC)各种滚动场景需求的插件。含有better-scroll.min.js
jquery endlessEndless Scroll.rar jquery endlessEndless Scroll.rar
js代码 [removed][removed] [removed][removed] [removed][removed] [removed] function showList(){ $("body").scrollmenu({ type:'cross', // bscroll:true, // animateIn:'bounceIn', // animateOut:'...
angular中实现上拉无限加载所用到的ng-infinite-scroll.js
// the correct offset 246 is used instead of 245. // // The ReduceColors function is changed according to Anders Melander's post // // so that a colour get converted to the precise colour if that ...
Scroll.js 一个非常小的但功能强大的javascript库,适用于Web开发人员。 特征 在Mac上为您提供Safari滚动体验。 优化的算法使滚动更加自然。 全帧性能。 js文件的大小太大,只有1kb(压缩)。 如何使用 只需将...
https://better-scroll.github.io/docs/zh-CN/plugins/mouse-wheel.htm https://better-scroll.github.io/docs/zh-CN/plugins/scroll-bar.html ...
新闻共分7类,新闻信息在此采集: 1 财经 http://finance.qq.com/l/201108/scroll_17.htm 2 科技 http://tech.qq.com/l/201512/scroll_02.htm 3 汽车 http://auto.qq.com/l/201512/scrollnews_02_2.htm 4 房产 ...
记住滚动 English |一个使用localStorage记住元素滚动位置的javascript插件,当再次访问该页面时,它可以自动滚动到最后一个访问位置。 压缩后只有3kb。文章介绍:演示版安装npm i remember-scroll --save CDN < ...
infinitescroll,滑动加载更多,压缩包内容为插件演示示例、常用参数介绍和使用注释
Recycler Fast Scroll Widget for RecyclerView fast scrolling, like Android's built-in fast scroll option for ListView. Supports any vertically scrolling LayoutManager, as well as proper integration...