评论案例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
textarea{
width: 400px;
height: 100px;
}
button {
position: relative;
left: 340px;
top: 5px;
border: 1px solid black;
border-radius: 80px;
}
li{
width: 370px;
text-decoration: none;
border: 1px solid #ccc;
border-radius: 30px;
}
</style>
</head>
<body>
<textarea id="text">请输入你的评论</textarea>
<br />
<button id="btn">发表评论</button>
<ul id="utx">
</ul>
</body>
<script>
var text = document.getElementById("text");
var btn = document.getElementById("btn");
var utx = document.getElementById("utx");
btn.onclick = function(){
var creatLiEle=document.createElement('li');
utx.insertBefore(creatLiEle,utx.firstElementChild);
creatLiEle.innerHTML = text.value + "<a href='javascript:;'>删除</a>"
text.value = ''
var del = document.querySelectorAll('a')
for (var i = 0; i < del.length; i++) {
del[i].onclick = function () {
utx.removeChild(this.parentNode);
}
}
}
</script>
</html>
轮播图案例(只实现图片转换):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
div {
width: 590px;
height: 470px;
background-color: #ccc;
margin: 50px auto;
position: relative;
}
img {
width: 590px;
height: 470px;
}
a {
display: block;
width: 25px;
height: 34px;
text-align: center;
line-height: 34px;
text-decoration: none;
color: #fff;
background-color: burlywood;
}
a:nth-of-type(1) {
position: absolute;
top: 218px;
border-radius: 0 50% 50% 0;
}
a:nth-of-type(2) {
position: absolute;
top: 218px;
right: 0;
border-radius: 50% 0 0 50%;
}
ul li {
list-style: none;
display: inline-block;
background-color: #fff;
width: 9.97px;
height: 9.97px;
border: 1px solid #fff;
border-radius: 50%;
/* text-align: center;
line-height: 25px; */
}
ul {
position: absolute;
bottom: 5px;
left: 150px;
}
</style>
</head>
<body>
<div>
<img src="img/car1.jpg" alt="">
<!-- <img src="img/guoqing02.jpeg" alt="">
<img src="img/guoqing03.jpeg" alt=""> -->
<a href="#"><</a>
<a href="#">></a>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<script>
var number = 1;
function run() {
number++;
if (number > 3) {
number = 1;
}
var img = document.querySelector("img");
img.src = "img/car" + number + ".jpg";
}
setInterval(run, 3000);
</script>
</body>
</html>
表格隔行变色案例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<table border="1px" cellspacing = '0' width = '500px' height='300px'>
<tr>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
</tr>
<tr>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
</tr>
<tr>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
</tr>
<tr>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
</tr>
<tr>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
</tr>
<tr>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
</tr>
<tr>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
</tr>
<tr>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
</tr>
<tr>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
</tr>
<tr>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
<td>1-1</td>
</tr>
</table>
<script>
//获取所有的tr标签
var trEles = document.querySelectorAll('tr');
//从trEles集合中取出元素,下标为偶数的元素表示的是奇数行,下标为奇数的元素表示的是偶数行
for(var i =0;i<trEles.length;i++){
if(i%2==0){
trEles[i].style.backgroundColor = '#ccc';
}else{
trEles[i].style.backgroundColor = '#f00';
}
}
</script>
</body>
</html>