操作属性
document .getElementByid("div1");根据ID来获取;
document .之后getElementByid("div1") .title = "你真美" ;
整个文档加载完之后执行的一个匿名函数;
function 匿名函数;
window .onload = function() {} 写在《script》标签里面;
通过id来查找文档中的唯一id
document getElementByid ("link") .href = "https://www.baidu.com",(跳转到网页)
还可以 例如 : var oA = document .getElentByid("link");
oA .href = "https://www.baidu.com"
oA .title = "百度搜索";
还可以读出来 : alert (oA.id) alert (oA.title);
对象 . 方法 ; 对象 . 属性 ;
js换肤
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="css/1.css" id="p2">
<script type="text/javascript">
window.onload=function () {
var b1 =document.getElementById('p');
var b2 =document.getElementById('p1');
b1.onclick = s1;
b2.onclick = s2;
}
function s1(){
var olick=document.getElementById("p2");
olick.href="css/1.css";
}
function s2(){
var olick=document.getElementById("p2");
olick.href="css/2.css";
}
</script>
</head>
<body>
<input type="button" name="" value="皮肤01" id="p" />
<input type="button" name="" value="皮肤02" id="p1" />
<div class="box1"></div>
<div class="box2"></div>
</body>
</html>
作业
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
ul{
margin: 0;
padding:0;
}
.p {
width: 960px;
height: 40px;
background-color:#55a8ea;
margin: 50px auto;
}
.p ul li{
list-style-type:none;
width: 100px;
float: left;
text-align: center;
}
.p ul li a{
text-decoration:none;
font-size: 14px;
color: white;
line-height: 42px;
}
.p ul li:hover{
background-color:#00619f;
}
.p1{
position: relative;
top: -10px;
left: -267px;
}
</style>
</head>
<body>
<div class="p">
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">网站建设</a></li>
<li><a href="#">程序开发</a></li>
<li><a href="#">网络营销</a></li>
<img src="new.png" class="p1">
<li><a href="#">企业VI</a></li>
<li><a href="#">案列展示</a></li>
<li><a href="#">联系我们</a></li>
</ul>
</div>
</body>
</html>
网友评论