js onload事件使用
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script>
//页面加载完成自动触发onload事件
onload = function () {
document.getElementById('span1').onclick = function () {
alert('ok');
}
};
</script>
</head>
<body>
<span id="span1">点击显示</span>
</body>
</html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script>
//页面加载完成自动触发onload事件
onload = function () {
document.getElementById('span1').onclick = function () {
alert('ok');
}
};
</script>
</head>
<body>
<span id="span1">点击显示</span>
</body>
</html>