<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Keywords" content="关键字,关键词">
<meta name="Description" content="描述和简介">
<title>Title</title>
<style type="text/css">
*{margin:0;padding:0;}
body,ul,li,ol,dl,dd,p,h1,h2,h3,h4,h5,h6{ margin:0;}
a{text-decoration:none;}
img{border:none;}
ol,ul{list-style:none;}
.box{
margin : 10px;
width: 100px;
height: 100px;
background: pink;
}
</style>
</head>
<body>
<!--
this指向
函数执行完之后,this指向默认指向window
.call()
.apply()
.bind()
-->
<div class="box">1</div>
<div class="box">2</div>
<div class="box">3</div>
<script>
/*
Fn();
function Fn(){
console.log(this);
};*/
var aBox = document.querySelectorAll(".box");
for(var i = 0; i < aBox.length; i++){
aBox[i].index = i;
aBox[i].onclick = function (){
console.log("紫霞!");
//chang(this);//传参时,This指向当前对象,否则默认指向window
chang1.call(this);//每一个函数都有call属性,call则指定函数中的this指向当前的this,点击谁,This就指向谁
};
};
/*
function chang(This){
console.log(This);
This.innerHTML = This.index;
This.className = "box click";
};*/
//chang1();
/* function chang1(){
console.log(this);
};*/
/*
Fn.call(aBox,40,10);//第一个参数代表this指向,只改变当前这一次,后面的参数对应传参
function Fn(x,y){
console.log(x+y);
console.log(this);
};
Fn(10,30);
*/
/*
Fn.apply(aBox , [10,20]);//改变当前这一次,后面的参数采用的是数组
function Fn(x,y){
console.log(this);
console.log(x+y);
};
*/
var a = 1;
document.onclick = function (){
alert(this.a);//this本来指向的是document,用了bind之后,this指向了window,才能找到a,因为document下没有a,a是在window下的。
console.log(this);//
}.bind(window);//改变this指向由document到Window
</script>
</body>
</html>
js控制跳转到上一个页面
var prevLink = document.referrer;
if($.trim(prevLink)==''){
location.href = 'www.example.com/index.html';
}else{
if(prevLink.indexOf('www.example.com')==-1){ //来自其它站点
location.href = 'www.example.com/index.html';
}
if(prevLink.indexOf('register.html')!=-1){ //来自注册页面
location.href = 'www.example.com/index.html';
}
location.href = prevLink;
}