setTimeout setInterval()延迟几秒
//执行一次
setTimeout('alert("hello")',3000);
//不停地执行
setInterval('alert("hello")',3000);
window.onload()方法:
该方法用于在网页加载完毕后立刻执行的操作,即当html加载完毕后,立刻执行某个方法等。
window.onload = function(){
var num = document.getElementById("t").value;
setTimeout(go(),num);
}
window.location 用于网页跳转
window.location.href="https://www.baidu.com";
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
function cj(){
//获取id为table的对象
var table = document.getElementById("mytable");
for(var i =0 ;i<10;i++){
//创建<tr></tr>
var tr = document.createElement("tr");
if(i%2==0){
tr.style.backgroundColor = "red";
}
//创建<td></td>
var td = document.createElement("td");
//将td放到tr中
tr.appendChild(td);
//td中的内容
td.innerText = "line"+i;
//将tr放到table中
table.appendChild(tr);
}
}
</script>
</head>
<body>
<table id="mytable">
</table>
<input type="button" value="创建" id="ccjj" onclick="cj();"/>
</body>
</html>
网友评论