JS实例(一)

1、移入移出div的变化

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

 

<head>

<style>

div {

width: 100px;

height: 100px;

background: red;

}

.box {

width: 200px;

height: 200px;

background: yellow;

}

</style>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>移入移出</title>


 

</head>

 

<body>

<div id="div1" οnmοuseοver="document.getElementById('div1').className='box';" οnmοuseοut="document.getElementById('div1').className='';">

 

</body>

 

</html>

 

2、动态改变block的出现

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

 

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>block的变化</title>

</head>

 

<body>

<label οnmοuseοver="document.getElementById('div1').style.display='block';" οnmοuseοut="document.getElementById('div1').style.display='none';">

<input type="checkbox" />自动登录</label>

<div id="div1">

yaoxiyao

</div>

</body>

 

</html>

 

3、点击按钮

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

 

<head>

<style>

input {

background: white;

}

.active {

background: yellow;

}

</style>

<script type="text/javascript">

window.onload = function() {

var oBtn = document.getElementsByTagName('input');

var i = 0;

 

for (i = 0; i < oBtn.length; i++) {

oBtn[i].onclick = function() {

for (i = 0; i < oBtn.length; i++) {

oBtn[i].className = '';

} //点击一个按钮是,先把所有的className变为空,即无样式,不是active

this.className = 'active'; //再把当前点击的按钮的className赋值为active

};

 

}

 

};

</script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

</head>

 

4、选项卡

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

 

<head>

<style>

input {

background: white;

}

.active {

background: yellow;

}

div {

width: 100px;

height: 100px;

background: #CCC;

display: none;

}

/*设为全部隐藏*/

</style>

<script type="text/javascript">

window.onload = function() {

var oBtn = document.getElementsByTagName('input');

var oDiv = document.getElementsByTagName('div');

 

var i = 0;

//分成两步

 

for (i = 0; i < oBtn.length; i++) {

oBtn[i].index = i; //第几个按钮的索引值是几

 

oBtn[i].onclick = function() {

for (i = 0; i < oBtn.length; i++) {

oBtn[i].className = '';

oDiv[i].style.display = 'none'; //所有的选项卡内容隐藏

} //点击一个按钮是,先把所有的className变为空,即无样式,不是active

this.className = 'active'; //再把当前点击的按钮的className赋值为active

//this表示当前点击的那个按钮 :oBtn[i]

oDiv[this.index].style.display = 'block';

//第一个的第一个div

};

 

}

 

};

</script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

</head>

<body>

<input class="active" type="button" value="yao" />

<input type="button" value="xiyao" />

<input type="button" value="yaoxiya" />

<div style="display:block;">姚</div>

<div>希瑶</div>

<div>姚希瑶</div>

</body>

</html>

 

5、网页换肤

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

<link id="link1" href="css1.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">

window.onload = function () {

var oLink = document.getElementById("link1");

var oBtn1 = document.getElementById("btn1");

var oBtn2 = document.getElementById("btn2");

alert(oLink.href)

oBtn1.onclick = function () {

oLink.href = 'css1.css';

}

oBtn2.onclick = function () {

oLink.href = 'css2.css';

}

}

</script>

</head>

 

<body>

 

<dl id="message">

<form>

<dt>

<strong>可以换肤的提交框:</strong>

<input id="btn1" type="button" value="皮肤1" />

<input id="btn2" type="button" value="皮肤2" />

</dt>

<dd>输入姓名:

<input class="text" type="text" />

</dd>

<dd>输入密码:

<input class="text" type="password" />

</dd>

<dd>请您留言:

<textarea></textarea>

</dd>

<dd class="center">

<input class="btn" type="submit" value="提交" />

</dd>

</form>

</dl>

 

</body>

 

</html>

css自行编写页面的颜色样式即可

 


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值