EduCoder js学习手册16 答案

编程入门 行业动态 更新时间:2024-10-27 04:35:16

EduCoder js学习手册16 <a href=https://www.elefans.com/category/jswz/34/1769768.html style=答案"/>

EduCoder js学习手册16 答案

浏览器对象模型使得JavaScript能够与浏览器对话,比如,告诉浏览器需要调到一个新的窗口。
JavaScript与浏览器对话主要依靠的就是window对象,window对象表示web浏览器的一个窗口或者窗体,window对象有一些特有的属性,比如location属性表示当前浏览器所在窗口的URL,即网址。
本实训主要讲解window对象的主要属性,以及建立在这些属性之上的JavaScript和浏览器的对话方式。通过学习本实训,你将体会到JavaScript如何操作浏览器,这是JavaScript强大之处的提现。

定时器

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><p onclick="handleTimer()">set timer then undo</p><script>var timeId;function timerTask() {console.log("this is timer task");}function handleTimer() {//请在此处编写代码/********** Begin **********///定时器 Id=window.setTimeout(a,b)  b毫秒后执行a//window.clearTimeout(Id)var timeId=window.setTimeout(timerTask(),2000);/********** End **********/}</script>
</body>
</html>


循环定时器

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><p onclick="task1()">this is task onea</p><p onclick="task2()">this is task two</p><p onclick="removeTask1()">try to remove task one</p><script>var timeId1;var timeId2;function timerTask1() {console.log("timerTask1!");}function timerTask2() {console.log("timerTask2!");}function task1() {timeId1 = window.setInterval(timerTask1,2000);}function task2() {timeId2 = window.setInterval(timerTask2,1500);}function removeTask1() {//请在此处编写代码/********** Begin **********///循环定时器 window.setInterval(a,b) 每隔b毫秒执行a任务window.clearInterval(timeId1);/********** End **********/}</script>
</body>
</html>


location对象

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><p onclick="openNew()">Click me to new page!</p><script>function openNew() {//请在此处编写代码/********** Begin **********///window.location 当前窗口页面的信息 location.href 当前页面的地址var loc=window.location;console.log(loc.host);loc.href="=newest";/********** End **********/}</script>
</body>
</html>


对话框

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><p onclick="inputName()">Click to input name!</p><script>function inputName() {var result;//请在此处编写代码/********** Begin **********///对话框//一 警告框 window.alert()//二 确认框 window.confirm()//三 输入框 window.prompt(a,b) 参数a为提示内容 参数b为默认输入result=window.prompt("your name","Xiao Ming");if(result==null){console.log("name cannot be null");}/********** End **********/}</script>
</body>
</html>


窗口

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><p onclick="openNewWindow()">open new window</p><script>var myWindow;function openNewWindow() {//请在此处编写代码/********** Begin **********///窗口//打开窗口 window.open(url,name,specs,replace)//url 文档的地址//name 窗口名//specs 打开窗口的尺寸//replace 控制新的窗口在阅览器的阅览历史里面如何显示//关闭窗口 result=window.open(url,name,specs,replace)//result.close();var myWindow=window.open("Demo.html","window_name");/********** End **********/}</script>
</body>
</html>

更多推荐

EduCoder js学习手册16 答案

本文发布于:2024-03-09 04:58:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1723883.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:答案   手册   EduCoder   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!