JavaScript学习(一些基本的互动的方法)
2020-01-15 10:32
417 查看
今天学习js一些基本的互动的方法
JavaScript-警告(alert 消息对话框)
[code]<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>alert</title> <script type="text/javascript"> function rec(){ var mychar="I love JavaScript"; alert(mychar); } </script> </head> <body> <input name="button" type="button" onClick="rec()" value="点击我,弹出对话框" /> </body> </html>
JavaScript-确认(confirm 消息对话框)
[code]<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>confirm</title> <script type="text/javascript"> function rec(){ var mymessage=confirm("你是女士吗"); if(mymessage==true) { document.write("你是女士!"); } else { document.write("你是男士!"); } } </script> </head> <body> <input name="button" type="button" onClick="rec()" value="点击我,弹出确认对话框" /> </body> </html>
JavaScript-提问(prompt 消息对话框)
[code]<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>prompt</title> <script type="text/javascript"> function rec(){ var score; //score变量,用来存储用户输入的成绩值。 score = prompt("你的分数"); if(score>=90) { document.write("你很棒!"); } else if(score>=75) { document.write("不错吆!"); } else if(score>=60) { document.write("要加油!"); } else { document.write("要努力了!"); } } </script> </head> <body> <input name="button" type="button" onClick="rec()" value="点击我,对成绩做评价!" /> </body> </html>
JavaScript-打开新窗口(window.open)
window.open(参数字符串:可选参数,设置窗口参数,各参数用逗号隔开。
[code]<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>window.open</title> <script type="text/javascript"> function Wopen(){ window.open('www.baidu.com','_blank','width=1366,height=768,menubar=yes,toolbar=yes, status=yes,scrollbars=yes') } </script> </head> <body> <input name="button" type="button" onClick="Wopen()" value="点击我,打开新窗口!" / > </body> </html>
JavaScript-关闭窗口(window.close)
close()关闭窗口
用法:
window.close(); //关闭本窗口
或
<窗口对象>.close(); //关闭指定的窗口
[code]<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>close()</title> <script type="text/javascript"> var mywin=window.open("www.baidu.com"); mywin.close(); </script> </head> <body> </body> </html>
任务
1、新窗口打开时弹出确认框,是否打开
提示: 使用 if 判断确认框是否点击了确定,如点击弹出输入对话框,否则没有任何操作。
2、通过输入对话框,确定打开的网址,默认为www.baidu.com
3、打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。
[code]<!DOCTYPE html> <html> <head> <title> new document </title> <meta http-equiv="Content-Type" content="text/html; charset=gbk"/> <script type="text/javascript"> function openWindow(){ var open=confirm("确认新建窗口打开网站吗?"); if(open == true) { var url = prompt("请输入网址","www.baidu.com"); if(url != null) { window.open(url,'_blank','width=400,height=500,menubar=no,toolbar=no') } else{ alert("再见"); } } } else{ alert("再见"); } } </script> </head> <body> <input type="button" value="新窗口打开网站" οnclick="openWindow()" /> </body> </html>
OK,今天的学习就到这里了
- 点赞
- 收藏
- 分享
- 文章举报
参数说明:
URL:可选参数,在窗口中要显示网页的网址或路径。如果省略这个参数,或者它的值是空字符串,那么窗口就不显示任何文档。 窗口名称:可选参数,被打开窗口的名称。 1.该名称由字母、数字和下划线字符组成。 2."_top"、"_blank"、"_self"具有特殊意义的名称。 _blank:在新窗口显示目标网页 _self:在当前窗口显示目标网页 _top:框架网页中在上部窗口中显示目标网页 3.相同 name 的窗口只能创建一个,要想创建多个窗口则 name 不能相同。 4.name 不能包含有空格。 参数字符串:可选参数,设置窗口参数,各参数用逗号隔开。
[code]<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>window.open</title> <script type="text/javascript"> function Wopen(){ window.open('www.baidu.com','_blank','width=1366,height=768,menubar=yes,toolbar=yes, status=yes,scrollbars=yes') } </script> </head> <body> <input name="button" type="button" onClick="Wopen()" value="点击我,打开新窗口!" / > </body> </html>
JavaScript-关闭窗口(window.close)
close()关闭窗口
用法:
window.close(); //关闭本窗口
或
<窗口对象>.close(); //关闭指定的窗口
[code]<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>close()</title> <script type="text/javascript"> var mywin=window.open("www.baidu.com"); mywin.close(); </script> </head> <body> </body> </html>
任务
1、新窗口打开时弹出确认框,是否打开
提示: 使用 if 判断确认框是否点击了确定,如点击弹出输入对话框,否则没有任何操作。
2、通过输入对话框,确定打开的网址,默认为www.baidu.com
3、打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。
[code]<!DOCTYPE html> <html> <head> <title> new document </title> <meta http-equiv="Content-Type" content="text/html; charset=gbk"/> <script type="text/javascript"> function openWindow(){ var open=confirm("确认新建窗口打开网站吗?"); if(open == true) { var url = prompt("请输入网址","www.baidu.com"); if(url != null) { window.open(url,'_blank','width=400,height=500,menubar=no,toolbar=no') } else{ alert("再见"); } } } else{ alert("再见"); } } </script> </head> <body> <input type="button" value="新窗口打开网站" οnclick="openWindow()" /> </body> </html>
OK,今天的学习就到这里了
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- 游戏开发中的一些基本方法
- 谈谈搜索引擎排序的一些基本方法
- UIView的一些基本方法理解:loadView、viewDidLoad、viewDidUnload、viewWillAppear、viewWillDisappear
- javascript操作select的一些基本方法总结
- 数据结构教材中hash的使用及一些基本概念和方法
- 我对ubuntu系统的一些感想(常见的安装软件方法以及基本知识)
- vim使用的一些基本方法
- 系统防刷的一些基本方法
- spring data jpa-------Repository的继承关系和一些基本方法的应用
- 根视图之UIView的一些基本方法
- 内存回收的一些基本方法 推荐
- Python中 pywt 小波分析库中的一些基本使用方法
- 一些关于git的基本使用方法
- OC一些基本类以及方法
- UIView的一些基本方法理解:loadView、viewDidLoad、viewDidUnload、viewWillAppear、viewWillDisappear
- mongodb的一些基本操作以及c++驱动的简单方法
- Mechanize模拟自然网页交互一些基本常用方法
- lucene.net的一些基本使用方法和概念
- GDI+和GDI的一些基本图形描绘方法的对比
- 网络配置的一些基本命令和方法