document.body onresize

document.body没有onresize()方法,window对象才有onresize() 方法, 但可以在<body>标签中写onresize属性,如:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>onresize</title>
</head>

<body onresize="test2()">
<script language="javascript">
function test1(){
	alert('test1');
}

function test2(){
	alert('here');
}

//document.body.attachEvent('onresize', test1);

window.attachEvent('onresize', test1);

</script>
</body>

</html>

使用document.body绑定onresize()方法无效:

document.body.attachEvent('onresize', test1);


1、要么使用onresize属性声明:

<body onresize="test2()">

2、要么使用window对象:

window.attachEvent('onresize', test1);



你可能感兴趣的:(document.body onresize)