-
<h1>操作成功</h1>
<span id="second" >5</span>
<span >秒后回到主页</span>
<a href="javascript:back();">返回</a>
<script type="text/javascript">
var num=document.getElementById("second").innerHTML;
//获取显示秒数的元素,通过定时器来更改秒数。
function count()
{
num--;
document.getElementById("second").innerHTML=num;
if(num==0)
{
location.assign("www.imooc.com");
}
}
setInterval("count()",1000);
//通过window的location和history对象来控制网页的跳转。
function back()
{
window.history.back();
}
<h1>操作成功</h1>
<p><span id='s'></span>秒回到主页<h2 id="back" onclick="tiaozhuan()">返回</h2></p>
//<script>
var i=setInterval(jian,1000);
var time=document.getElementById('s');
var num=5;
function jian(){
time.innerHTML=num;
num--;
if(num<0)
{
clearInterval(i);
location.href="https://www.baidu.com";
}
}
function tiaozhuan(){
if(history.length>0)
history.forward(1);
}
</script>
查看全部 -
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<form>
请选择你爱好:<br>
<input type="checkbox" name="hobby" id="hobby1"> 音乐
<input type="checkbox" name="hobby" id="hobby2"> 登山
<input type="checkbox" name="hobby" id="hobby3"> 游泳
<input type="checkbox" name="hobby" id="hobby4"> 阅读
<input type="checkbox" name="hobby" id="hobby5"> 打球
<input type="checkbox" name="hobby" id="hobby6"> 跑步 <br>
<input type="button" value = "全选" onclick = "checkall();">
<input type="button" value = "全不选" onclick = "clearall();">
<p>请输入您要选择爱好的序号,序号为1-6:</p>
<input id="wb" name="wb" type="text" >
<input name="ok" type="button" value="确定" onclick = "checkone();">
</form>
<script type="text/javascript">
function checkall()
{
var hobby = document.getElementsByTagName("input");
// 任务1
for(i=0;i<hobby.length;i++)
{
if(hobby[i].type=="checkbox")
{
hobby[i].checked=true;
}
}
}
function clearall(){
var hobby = document.getElementsByName("hobby");
for(var i=0;i<hobby.length;i++)
{
hobby[i].checked=false;
}
}
function checkone(){
var j=document.getElementById("wb").value;
// 任务3
var hobby=document.getElementById("hobby"+j);
hobby.checked=true;
}
</script>
</body>
</html>
查看全部 -
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<!--先编写好网页布局-->
<h3>操作成功</h3>
<p><span id="sqtimen"></span>秒后回到首页<a href="#" onclick="goback(1)">返回</a></p>
<script type="text/javascript">
var num=5;
function change()
{
if (num==0)
{
clearTimeout(i);
location.assign("https://www.imooc.com");
}
else
{
document.getElementById("sqtimen").innerText=num;
num=num-1;
var i=setTimeout(change,1000);
}
function goback()
{
window.history.back();
}
}
change ();
</script>
</body>
</html>
查看全部 -
代码不全,需再做一遍。
查看全部 -
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<form>
请选择你爱好:<br>
<input type="checkbox" name="hobby" id="hobby1"> 音乐
<input type="checkbox" name="hobby" id="hobby2"> 登山
<input type="checkbox" name="hobby" id="hobby3"> 游泳
<input type="checkbox" name="hobby" id="hobby4"> 阅读
<input type="checkbox" name="hobby" id="hobby5"> 打球
<input type="checkbox" name="hobby" id="hobby6"> 跑步 <br>
<input type="button" value="全选" onclick="checkall();">
<input type="button" value="全不选" onclick="clearall();">
<p>请输入您要选择爱好的序号,序号为1-6:</p>
<input id="wb" name="wb" type="text">
<input name="ok" type="button" value="确定" onclick="checkone();">
</form>
<script type="text/javascript">
function checkall() {
var hobby = document.getElementsByTagName("input");
//alert(hobby.length);
for (i = 0; i < hobby.length; i++) {
hobby[i].checked = "checked";
}
}
function clearall() {
var hobby = document.getElementsByName("hobby");
//alert(hobby.length);
for (i = 0; i < hobby.length; i++) {
hobby[i].checked = false;
}
}
function checkone() {
var j = document.getElementById("wb").value;
switch (j) {
case "1":
clearall();
document.getElementById("hobby1").checked = "checked";
break;
case "2":
clearall();
document.getElementById("hobby2").checked = "checked";
break;
case "3":
clearall();
document.getElementById("hobby3").checked = "checked";
break;
case "4":
clearall();
document.getElementById("hobby4").checked = "checked";
break;
case "5":
clearall();
document.getElementById("hobby5").checked = "checked";
break;
case "6":
clearall();
document.getElementById("hobby6").checked = "checked";
break;
default:
alert("数值有误,请重新输入~");
}
}
</script>
</body>
</html>
查看全部 -
onunload卸载事件调用函数用:window.onunload=提示函数
查看全部 -
window.open('pageURL','type','parameter');
type:_blank / _self
parameter:宽高、定位、toolbar工具栏、menubar菜单栏、scrollbars滚动条、status状态栏
查看全部 -
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计时器</title>
<script type="text/javascript">
var num=0;
var i;
function startCount(){
document.getElementById('count').value=num;
num=num+1;
i=setTimeout("startCount()",1000);
}
function stopCount(){
clearTimeout(i);
}
</script>
</head>
<body>
<form>
<input type="text" id="count" />
<input type="button" value="Start" onclick="startCount()" />
<input type="button" value="Stop" onclick="stopCount()" />
</form>
</body>
</html>
查看全部 -
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>定时器</title>
<script type="text/javascript">
var attime;
function clock(){
var time=new Date();
attime=time.getHours()+":"+time.getMinutes()+":"+time.getSeconds();
document.getElementById("clock").value = attime;
}
setInterval("clock()",1000);
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="50" />
</form>
</body>
</html>
查看全部 -
这是个好题,
考察了时间对象:new Date、getFullYear(),getMonth()、getDate()、getDay();
分隔符:split;
数组的定义;
循环算法;
选定元素:slice;
parseInt()函数的用法:parseInt() 函数可解析一个字符串,并返回一个整数
<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系好安全带,准备启航</title>
<script type="text/javascript">
//通过javascript的日期对象来得到当前的日期,并输出。
var mydate=new Date();
var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
document.write(mydate+"<br/>");
//成绩是一长窜的字符串不好处理,找规律后分割放到数组里更好操作哦
var scoreStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
var scoreArr=scoreStr.split(";");
//从数组中将成绩撮出来,然后求和取整,并输出。
var sum=0;
for (var i = 0; i < scoreArr.length; i++)
{
sum=sum+parseInt(scoreArr[i].slice(3,5));
}
var avg=parseInt(sum/(scoreArr.length));
//从数组中将成绩撮出来,然后求和取整,并输出。
document.write(mydate.getFullYear()+"年"+mydate.getMonth()+"月"+mydate.getDate()+"日"+" "+" "+" "+weekday[mydate.getDay()]+" "+"总分:"+sum+" "+" "+"平均分:"+avg);
</script>
</head>
<body>
</body>
</html>
查看全部 -
<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
<script type="text/javascript">
function count(){
var num1,num2,fuhao,jieguo;
var fuhao=document.getElementById('select').value;
var num1=parseInt(document.getElementById('txt1').value);
var num2=parseInt(document.getElementById('txt2').value);
switch(fuhao){
case "+" :
jieguo=num1+num2;
break;
case "-" :
jieguo=num1-num2;
break;
case "*" :
jieguo=num1*num2;
break;
case "/" :
jieguo=num1/num2;
break;
}
document.getElementById('fruit').value = jieguo;
alert(jieguo);
}
</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>
查看全部 -
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb" />
</head>
<body>
<!--先编写好网页布局-->
<p>操作成功</p>
<form>
<a href="file:///Volumes/SD/%E7%AC%AC%E4%BA%8C%E4%B8%AA%E9%A1%B5%E9%9D%A2.html">点击跳到第二个页面</a>
<br/>
<input type="text" id="count" />
<span>秒后返回主页</span>
<br />
<input type="button" value="进入下一页" onclick="GoForward()">
<input type="button" value="进入前一页" onclick="GoBack()">
</form>
</body>
<script type="text/javascript">
//获取显示秒数的元素,通过定时器来更改秒数。
var num = 10;
var i;
function startCount() {
document.getElementById('count').value = num;
num = num - 1;
if (num !== 0) {
i = setTimeout("startCount()", 1000);
}
if (num == 0) {
//通过window的location和history对象来控制网页的跳转。
window.location.replace("https://www.imooc.com/u/index/allcourses");
}
}
function GoForward(){
window.history.forward();
}
function GoBack() {
//window.history.back();
window.history.go(-1);
}
startCount();
</script>
</html>
查看全部 -
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Math </title>
<script type="text/javascript">
document.write(Math.round(Math.random()*10));
</script>
</head>
<body>
</body>
</html>
查看全部 -
<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
<script type="text/javascript">
function count(){
//获取第一个输入框的值
var txt1=parseInt(document.getElementById("txt1").value);
//获取第二个输入框的值
var txt2=parseInt(document.getElementById("txt2").value);
var result;
//获取选择框的值
//获取通过下拉框来选择的值来改变加减乘除的运算法则
var fuhao=document.getElementById('select').value
//设置结果输入框的值
switch(fuhao)
{
case "+":
result=txt1+txt2;
break;
case "-":
result=txt1-txt2;
break;
case "*":
result=txt1*txt2;
break;
case "/":
result=txt1/txt2;
break;
}
document.getElementById('fruit').value=result;
}
</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>
查看全部 -
<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>流程控制语句</title>
<script type="text/javascript">//第一步把之前的数据写成一个数组的形式,定义变量为
var infos=new Array(
['小A','女',21,'大一'],
['小B','男',23,'大三'],
['小C','男',24,'大四'],
['小C','男',24,'大四'],
['小D','女',21,'大一'],
['小E','女',22,'大四'],
['小F','男',21,'大一'],
['小G','女',22,'大二'],
['小H','女',20,'大三'],
['小I','女',20,'大一'],
['小J','男',20,'大三']
);
//第一次筛选,找出都是大一的信息
for(var i=0; i<infos.length;i++){
for(var j=0;j<infos[i].length;j++){//循环二维数组
if(infos[i][j]=='大一'){//判断条件大一
document.write(infos[i]+"<br />"); //输出含大一的数组
}
}
}
//第二次筛选,找出都是女生的信息
//对不起,找不出女生!!!!!</script>
查看全部
举报