Js中的bom

(1)window对象

弹块的方法

提示块:

window.alert("提示信息");

Code:

var res = alert("xxx");

alert(res);

确认块:

window.confirm("确认信息");

有返回值:如果点击确认返回true,如果点击取消返回false

code:

var res = confirm("您确认要删除吗?");

alert(res);

输入框:prompt("提示信息");

有返回值:如果点击确认返回输入框的文本 点击取消返回null

Code:

var res = prompt("请输入密码?");

alert(res);

open方法:

window.open("url地址");        

Code:

open("../jsCore/demo10.html");

定时器:

setTimeout(函数,毫秒值);

Code:

setTimeout(

function(){

alert("xx");

},

3000

);

clearTimeout(定时器的名称); //清除定时器

Code:

<script type="text/javascript">

var timer;

var fn = function(){

alert("x");

timer = setTimeout(fn,2000);

};

var closer = function(){

clearTimeout(timer);

};

fn();

</script>

</head>

<body>

<input type="button" value="button" onclick="closer()">

</body>

setInterval(函数,毫秒值);

Code:

<script type="text/javascript">

var timer = setInterval(

function(){

alert("nihao");

},

2000

);

var closer = function(){

clearInterval(timer);

};

</script>

</head>

<body>

<input type="button" value="button" onclick="closer()">

</body>

   

Code:注册后5秒钟跳转首页

<script type="text/javascript">

var time = 5;

var timer;

timer = setInterval(

function(){

var second = document.getElementById("second");

if(time>=1){

second.innerHTML = time;

time--;

}else{

clearInterval(timer);

location.href="../jsCore/demo10.html";

}

},

1000

);

</script>

   

   

</head>

<body>

恭喜您注册成功,<span id="second" style="color: red;">5</span>秒后跳转到首页,如果不跳转请<a href="../jsCore/demo10.html">点击这里</a>

</body>

(2)location        

location.href="url地址";

(3)history:历史对象

back(); 回退

forward();前进

go();

code:

<input type="button" value="上一页" onclick="history.back()">

<input type="button" value="下一页" onclick="history.forward()">

   

<input type="button" value="上一页" onclick="history.go(-1)">

<input type="button" value="下一页" onclick="history.go(1)">

  

 

posted @ 2017-04-17 22:55  殷瑜泰  阅读(251)  评论(0编辑  收藏  举报