<img id="light" src="img/off.gif">
<script>
/*
1、获取图片对象
2、绑定点击事件
3、切换图片
使用flag标注状态
* */
var element = document.getElementById("light");
var flag = false;//关闭状态
element.onclick = function (ev) {
if(flag){//如果灯开着
element.src = "img/off.gif";
flag = false;
}else{
element.src = "img/on.gif";
flag = true;
}
}
</script>
02、设置时间弹出链接 <p>
<span id="time">5</span>之后跳转
</p>
<script>
var data = 5;
function fun(){
data--;
if(data<=0){
location.href="https://www.sina.cn";
}
time.innerHTML = data;
}
setInterval(fun,1000);
</script> 03、轮播图 <img src="img/img/banner_1.jpg" id="img" width="100%" />
<script>
var number =1;
function fun(){
number++;
if(number>3){
number=1;
}
var img =document.getElementById("img");
img.src="img/img/banner_"+number+".jpg";
}
setInterval(fun,3000);
</script>
<script>
var selectAll =document.getElementById("selectAll");
var cbs =document.getElementsByName("cb");
selectAll.onclick=function(){
for (var i=0;i<cbs.length;i++) {
cbs.checked = true;
}
}
var unSelectAll =document.getElementById("unSelectAll");
var cbs =document.getElementsByName("cb");
unSelectAll.onclick=function(){
for (var i=0;i<cbs.length;i++) {
cbs.checked = false;
}
}
var selectRev=document.getElementById("selectRev");
var cbs =document.getElementsByName("cb");
selectRev.onclick=function(){
for (var i=0;i<cbs.length;i++) {
cbs.checked = !cbs.checked;
}
}
</script>
</div>
</body>
</html>
07.输出时间
<script>
var myDate =new Date();
var year =myDate.getFullYear();
var month =myDate.getMonth()+1;
var day =myDate.getDate();
var hour =myDate.getHours();
var min =myDate.getMinutes();
var second = myDate.getSeconds();
//如果为单数时,在前面补0
year = year < 10 ? "0" :year;
month =month <10 ? "0" :month;
day =day < 10 ? "0" :day;
hour = hour <10 ? "0" :hour;
min =min <10 ? "0" :min;
second = second <10 ? "0" :second;
//输出时间
document.write(year+"-"+month +"-"+day+"-"+hour+"-"+min+"-"+second);
</script>
<div id="div1">
</div>
<script>
function creat() {
var row = document.getElementById("row").value;
var col = document.getElementById("col").value;
var div1 = document.getElementById("div1");