Css定位
position:配合方向值一起使用 top left right bottom
static 没有定位
relaive 相对定位 没有脱离文档流
position: relative;
right: -100px;
top: 50px;
搭配方向一起使用
相对定位向右上移动
absolute 绝对定位 完全脱离文档流(和浮动会脱离文档流一个道理,只是和浮动右区别)
position: absolute;
right: 0px;
top:0;
绝对定位到右上,在你选中的块的范围内
fixed 固定定位 完全脱离文档流
相对窗体进行固定定位,在某一个位置不变
position: fixed;
right: 0px;
bottom: 0px;
固定在浏览器窗口的右下角
js
javascript的组成
ECMAScript 核心语法
DOM 浏览器对象模型
操作html元素的方法和接口
BOM
与浏览器进行交互的方法和接口
js的使用方式:
行内:结合事件一起使用
内部:定义script标签对
外部:使用script标签,引入外部的js文件
js的使用
js的出现位置
script可以出现在html中的任意位置
推荐使用位置
1、head中
优点:便于后期的维护
缺点:有可能获取不到元素,因为head标签在html的上面要先走head的代码,那么定义在body的元素就有可能拿不到元素
js的调用方式()
1、alert()弹出框
缺:阻塞页面的加载,需要手动点击才能继续
2、document.write()页面中写出
当页面加载完成之后,再触发document.write()的执行,会覆盖页面
可以写出内容以及标签
3、console.log()推荐使用
console.info()
console.warn()
console.error()
js变量的定义
声明的同时赋值
var 变量名=变量值;
先声明后赋值
var 变量名;
变量名=变量值;
数据类型
基础数据类型
String 字符串类型 —控制台为黑色
把内容定义在一对’'或者""之间,但是要求前后引号一致
可以使用转义字符
Number 数值型 —蓝色的
NaN
not
a
number
出现NaN类型的情况
1)直接赋值NaN
2)无法正常运算出结果的时候会出现NaN类型
Boolean类型 —蓝色的
false
true
严格区分大小写
Undefined 未定义 —灰色的
1)直接赋值undefined
2)变量只声明未赋值
Null 空 —灰色的
1)直接赋值Null
2)获取不到
null是没有定义,没有
undefined是有,但是没有值
function 函数
使用关键字function定义函数
function fn(name){
console.log(name+“呵呵呵呵”);
}
fu();
复合数据类型
对象 Object
{
key:value,
key:value
…
}
对象中的数据都是键值对形式存在的
每两个键值对之间使用,分隔,最后一个键值对后不存在,
key满足标识符的标识符的命名规范,如果不满足定义在一对引号中
value可以是任意数据类型的值
typeof操作符
判断数据的数据类型
typeof 数据
typeof(数据)
返回数据类型的小写形式
<script>
var a=123;
console.log(typeof a);
console.log(typeof("哈哈"));
console.log(typeof(false));
console.log(typeof(null));
console.log(typeof(undefined));
console.log(typeof(function(){}));
console.log(typeof({}));
</script>
把任意类型转换成为一下三种形式:
String类型
String(数据)
相当于在数据的前后添加一对引号
Number类型
Number(数据)
String
‘’ 0
" " 0
“纯数字” 纯数字
“非纯数字” NaN
Boolean
true 1
false 0
Null 0
Undefined NaN
console.log(Number(''));
console.log(Number(" "));
console.log(Number("123"));
console.log(Number("123abc"));
console.log(Number(false));
console.log(Number(true));
console.log(Number(null)); //0
console.log(Number(undefined)); //NaN
Boolean类型
Boolean(数据)
String
‘’ false
" " true
“纯数字” true
“非纯数字” true
Number
0 false
1 true
其他数字 true
NaN false
Null false
Undefined false
console.log(Boolean('')); //false
console.log(Boolean(" "));
console.log(Boolean("123"));
console.log(Boolean("123abc"));
console.log(Boolean(0)); //false
console.log(Boolean(1));
console.log(Boolean(123));
console.log(Boolean(NaN)); //false
console.log(Boolean(null)); //false
console.log(Boolean(undefined)); //false
js的数组
数组: 存储多个数据
存储任意类型的数据
长度可以改变
有索引的概念,可以根据索引操作数据中的数据
提供了一些列的方法操作数组
长度属性 数组名.length
使用数组中的数据 数据名[索引] 赋值,修改值,获取值
(js中没有容器,因为在Java中容器能干的事儿,js中的数组都干了,js中的和Java中的容器时不一样的)
如何定义数组:
new Array() 通过new关键字创建一个空数组
new Array(值1,值2…) 通过new关键字创建数组并同时赋值
[值1,值2,…] 字面量方式创建数组----推荐
//1.new
var arr=new Array();
console.log(arr);
//2.new Array(1,2,3);
var arr2=new Array(1,2,3,4,5);
console.log(arr2);
//数组的遍历
for(var i=0;i<=arr3.length-1;i++){
console.log(arr3[i]);
}
//2.for..in
for(var a in arr3){ //a作为索引
console.log(arr3[a]);
}
//3.foreach
arr3.forEach(function(e,i){
console.log(e,i);
});
= 赋值
== 比较值是否相等
=== 比较值和类型是否相等
如果类型就不相等,不会进一步比较值
&&
操作数为boolean类型时-->一个为假就是假,两个都为真就是真
操作数有其他类型时-->第一个操作数如果转为boolean类型为true,结果就是第二个操作数的值
第一个操作数如果转为boolean类型为false,结果就是第一个操作数的值
||
操作数为boolean类型时-->一个为真就是真,两个都为假就是假
操作数有其他类型时-->
第一个操作数如果转为boolean类型为true,,结果就是第一个操作数的值
第一个操作数如果转为boolean类型为false,,结果就是第二个操作数的值
! 非 取反
当操作数为其他类型时候,先转为boolean类型,再进行取反
!!
布尔类型-->取反再取反,就是本身
非布尔类型->转为boolean类型
块 {}
js中的 {}不成作用域
js中的作用域只看函数
console.log(11=='11'); //true
console.log(11==='11'); //false
console.log(false==0); //true
console.log(true && false);
console.log(true && 1);
console.log(0 && false);
console.log('n' && undefined);
console.log(true || 1); //true
console.log(0 || 'a'); //'a'
console.log('n' || undefined); //'n'
console.log(!0);
console.log(!null);
//块
{
var ccc=100;
}
console.log(ccc);