为了账号安全,请及时绑定邮箱和手机立即绑定
课程 \ JavaScript进阶篇

JavaScript进阶篇

7-3 返回/设置年份方法
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>获得年份 </title>
<script type="text/javascript">
var mydate=new Date();
var myyear=mydate.getFullYear(2018);
document.write("年份:"+myyear);
</script>
</head>
<body>
</body>
</html>
2018-04-27 查看完整代码
7-1 什么是对象
<html>
<head>
<script type="text/javascript">
var myarray=new Array(5);
var mynum=myarray.length;
document.write("数组长度:"+mynum);
</script>
</head>
<body>
</body>
</html>
2018-04-27 查看完整代码
6-11 编程练习
<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
<script type="text/javascript">
function count(){
//获取第一个输入框的值
var txt1=document.getElementById("txt1").value;
//获取第二个输入框的值
var txt2=document.getElementById("txt2").value;
//获取选择框的值
var select=document.getElementById("select").value;
//获取通过下拉框来选择的值来改变加减乘除的运算法则
//设置结果输入框的值
var fruit=txt1(select)txt2;
}
</script>
</head>
<body>
<input type='text' id='txt1' />
<select id='select'>
<option value='+'>+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type='text' id='txt2' />
<input type='button' value=' = ' /> <!--通过 = 按钮来调用创建的函数,得到结果-->
<input type='text' id='fruit' />
</body>
</html>
2018-04-27 查看完整代码
6-10 卸载事件(onunload)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> 卸载事件 </title>
<script type="text/javascript">
window.onunload = onunload_message;
function onunload_message(){
alert("您确定离开该网页吗?");
}
</script>
</head>
<body>
欢迎学习JavaScript。
</body>
</html>
2018-04-27 查看完整代码
6-9 加载事件(onload)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> 加载事件 </title>
<script type="text/javascript">
function message(){
alert("加载中,请稍等…"); }
</script>
</head>
<body onload="message()">
欢迎学习JavaScript。
</body>
</html>
2018-04-27 查看完整代码
6-8 文本框内容改变事件(onchange)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> 文本框内容改变事件 </title>
<script type="text/javascript">
function message(){
alert("您改变了文本内容!"); }
</script>
</head>
<body>
<form>
个人简介:<br>
<textarea name="summary" cols="60" rows="5" onchange="message()">请写入个人简介,不少于200字!</textarea>
</form>
</body>
</html>
2018-04-27 查看完整代码
6-7 内容选中事件(onselect)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> 内容选中事件 </title>
<script type="text/javascript">
function message(){
alert("您触发了选中事件!"); }
</script>
</head>
<body>
<form>
个人简介:<br>
<textarea name="summary" cols="60" rows="5" onselect="message()">请写入个人简介,不少于200字!</textarea>
</form>
</body>
</html>
2018-04-27 查看完整代码
6-6 失焦事件(onblur)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> 失焦事件 </title>
<script type="text/javascript">
function message(){
alert("请确定已输入密码后,再移开!"); }
</script>
</head>
<body>
<form>
用户:<input name="username" type="text" value="请输入用户名!" onblur="message()">
<br/>
密码:<input name="password" type="text" value="请输入密码!" >
</form>
</body>
</html>
2018-04-27 查看完整代码
6-5 光标聚焦事件(onfocus)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 光标聚焦事件 </title>
<script type="text/javascript">
function message(){
alert("请选择,您现在的职业!");
}
</script>
</head>
<body>
请选择您的职业:<br>
<form>
<select name="career" onfocus="message()">
<option>学生</option>
<option>教师</option>
<option>工程师</option>
<option>演员</option>
<option>会计</option>
</select>
</form>
</body>
</html>
2018-04-27 查看完整代码
6-4 鼠标移开事件(onmouseout)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>鼠标移开事件 </title>
<script type="text/javascript">
function message(){
alert("不要移开,点击后进行慕课网!"); }
</script>
</head>
<body>
<form>
<a href="http://www.imooc.com" onmouseout="message()">点击我</a>
</form>
</body>
</html>
2018-04-27 查看完整代码
6-3 鼠标经过事件(onmouseover)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 鼠标经过事件 </title>
<script type="text/javascript">
function message(){
confirm("请输入密码后,再单击确定!"); }
</script>
</head>
<body>
<form>
密码:<input name="password" type="password" >
<input name="确定" type="button" value="确定" onmouseover="message()"/>
</form>
</body>
</html>
2018-04-27 查看完整代码
6-2 鼠标单击事件( onclick )
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>单击事件 </title>
<script type="text/javascript">
function openwin(){
window.open('http://www.imooc.com','_blank','height=600,width=400,top=100,toolbar=no,left=0,menubar=no,scrollbars=no,status=no');}
</script>
</head>
<body>
<form>
<input name="点击我" type="button" value="点击我" onclick="openwin()"/>
</form>
</body>
</html>
2018-04-27 查看完整代码
5-6 编程练习
<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函数</title>

<script type="text/javascript">

//定义函数
function bigone(a,b){
var a,b;
//函数体,判断两个整数比较的三种情况
if(a>=b)
return a;
else
return b;
}

//调用函数,实现下面两组数中,返回较大值。
document.write(" 5 和 4 的较大值是:"+bigone(5,4)+"<br>");
document.write(" 6 和 3 的较大值是:"+bigone(6,3) );




</script>
</head>
<body>
</body>
</html>
2018-04-26 查看完整代码
5-5 返回值的函数
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>返回值函数</title>
<script type="text/javascript">
function app2(x,y)
{ var sum,x,y;
sum = x * y;
return sum;
}
var req1=app2(5,6);
var req2=app2(2,3);
var sumq=req1+req2;
document.write("req1的值:"+req1+"<br/>");
document.write("req2的值:"+req2+"<br/>");
document.write(req1+"与"+req2+"和:"+sumq);
</script>
</head>
<body>
</body>
</html>
2018-04-26 查看完整代码
5-4 有参数的函数
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函数传参</title>
<script type="text/JavaScript">
function add(x,y,z)
{
sum = x + y +z;
document.write(x+"、"+y+"、"+z+"和:"+sum+"<br/>");
}
add(5,8,3);
add(7,1,4);
</script>
</head>
<body>
</body>
</html>
2018-04-26 查看完整代码
5-3 函数调用
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函数调用</title>
<script type="text/javascript">
function tcon()
{
alert("恭喜你学会函数调用了!");
}
</script>
</head>
<body>
<form>
<input type="button" value="点点我" onclick="tcon()">
</form>
</body>
</html>
2018-04-26 查看完整代码
5-2 定义函数
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>定义函数</title>
<script type="text/javascript">
function sub2() //定义函数
{
sub=5-2;
alert("5和2的差:"+sub);
}
</script>
</head>
<body>
<form>
<input type="button" value="点击我" onclick="sub2()" />
</form>
</body>
</html>
2018-04-26 查看完整代码
意见反馈 帮助中心 APP下载
官方微信