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

JavaScript进阶篇

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>
2015-04-25 查看完整代码
6-11 编程练习
<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
<script type="text/javascript">
function count(){

//获取第一个输入框的值
var x=document.getElementById("txt1").value;
//获取第二个输入框的值
var y=document.getElementById("txt2").value;
//获取选择框的值
var z=document.getElementById("select").value;
//获取通过下拉框来选择的值来改变加减乘除的运算法则
switch (z)
{
//设置结果输入框的值
case "+":
document.getElementById("fruit").value =parseInt(x)+parseInt(y);
break;
case "-":
document.getElementById("fruit").value =parseInt(x)-parseInt(y);
break;
case "*":
document.getElementById("fruit").value =parseInt(x)*parseInt(y);
break;
case "/":
document.getElementById("fruit").value =parseInt(x)/parseInt(y);
break;
}
}
</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=' = ' onclick="count()"/> <!--通过 = 按钮来调用创建的函数,得到结果-->
<input type='text' id='fruit' />
</body>
</html>
2015-04-25 查看完整代码
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>
2015-04-25 查看完整代码
6-9 加载事件(onload)
<!DOCTYPE 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>
2015-04-25 查看完整代码
6-8 文本框内容改变事件(onchange)
<!DOCTYPE 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>
2015-04-25 查看完整代码
6-7 内容选中事件(onselect)
<!DOCTYPE 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>
2015-04-25 查看完整代码
6-6 失焦事件(onblur)
<!DOCTYPE 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="请输入用户名!" >
密码:<input name="password" type="text" value="请输入密码!" onblur="message()">
</form>
</body>
</html>
2015-04-25 查看完整代码
6-5 光标聚焦事件(onfocus)
<!DOCTYPE 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>
2015-04-25 查看完整代码
6-4 鼠标移开事件(onmouseout)
<!DOCTYPE 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>
2015-04-25 查看完整代码
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>
2015-04-25 查看完整代码
6-2 鼠标单击事件( onclick )
<!DOCTYPE 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>
2015-04-25 查看完整代码
5-6 编程练习
<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函数</title>

<script type="text/javascript">

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

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




</script>
</head>
<body>
</body>
</html>
2015-04-25 查看完整代码
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>
2015-04-25 查看完整代码
5-4 有参数的函数
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函数传参</title>
<script type="text/JavaScript">
function add3(x,y,z)
{
sum = x + y +z;
document.write(x+"、"+y+"、"+z+"和:"+sum+"<br/>");
}
add3(5,8,3);
add3(7,1,4);
</script>
</head>
<body>
</body>
</html>
2015-04-25 查看完整代码
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>
2015-04-25 查看完整代码
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>
2015-04-25 查看完整代码
4-10 编程练习
<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>流程控制语句</title>
<script type="text/javascript">

//第一步把之前的数据写成一个数组的形式,定义变量为 infos
var infos=
[
["小A","女",21,"大一"],
["小B","男",23,"大三"],
['小C','男',24,'大四'],
['小D','女',21,'大一'],
['小E','女',22,'大四'],
['小F','男',21,'大一'],
['小G','女',22,'大二'],
['小H','女',20,'大三'],
['小I','女',20,'大一'],
['小J','男',20,'大三']
];

//第一次筛选,找出都是大一的信息
//第二次筛选,找出都是女生的信息
for(i=0;i<infos.length;i++)
{
if(infos[i][3]=="大一" && infos[i][1]=="女")
document.write(infos[i][0]+"<br>");
}
</script>
</head>
<body>
</body>
</html>
2015-04-25 查看完整代码
意见反馈 帮助中心 APP下载
官方微信