`
java-mans
  • 浏览: 11430634 次
文章分类
社区版块
存档分类
最新评论

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);



分享到:
评论

相关推荐

    javascript小技巧

    document.all.topmsg.style.left=document.body.scrollLeft+document.body.clientWidth/2-document.all.topmsg.offsetWidth/2 document.all.topmsg.style.top=document.body.scrollTop+document.body.clientHeight-...

    index.html

    &lt;!... 跳动的小球 *{margin:0;... document.body.appendChild(div); setTimeout(()=&gt;{ document.body.removeChild(div); div = null; },1000) } })(); &lt;/body&gt; &lt;/html&gt;

    jQuery监听浏览器窗口大小的变化实例

    方法一:在标签上加入 onLoad=”” onResize=”” 方法 写上对应的方法即可 方法二:[removed]=function(){///…..} 在方法里面写上对应的代码即可 着两种方法基本都可以解决问题。 [removed] function adjust...

    浅谈javascript属性onresize

    浅谈javascript属性onresize //获取屏幕宽度并动态赋值 ...else if ((document.body) && (document.body.clientWidth)) winWidth = document.body.clientWidth; //获取窗口高度 if (window.innerHeigh

    推拉门式菜单

    window.onresize=regenerate&quot;,400)}window.onload=regenerate2if (document.all){document.write(‘‘)themenu=document.all.slidemenubar2.stylerightboundary=0leftboundary=-150}else{themenu=document....

    1234.htmlyangzihang

    document.body.appendChild(this.canvas); window.addEventListener("resize", () =&gt; this.onResize()); this.onResize(); this.updateBound = this.update.bind(this); requestAnimationFrame(this....

    IE下[removed] 多次调用与死循环bug处理方法介绍

    解决方案: 代码如下:// IE浏览器下将onresize事件放在div上if(navigator.userAgent && navigator.userAgent.toLowerCase().indexOf(“msie”)&gt;-1){ document.body[removed] = ‘&lt;div onresize=”...

    在b/s开发中经常用到的javaScript技术整理

    在b/s开发中经常用到的javaScript技术整理 一、验证类 1、数字验证内 1.1 整数 1.2 大于0的整数 (用于传来的ID的验证) ... 4.3 判断字符由字母和数字,... var all = eval(\"document.hrong.\"+ str); if ...

    easy-div:网页中使用的一个方便的 div 元素

    简单的div 该模块为您的演示和原型启动和运行提供了一个非常简单的 div 元素。 非常适合与 Beefy 一起使用。 例子 var easyDiv = require ( 'easy-div' ) ;... document . body ) ; 请参阅demo/demo.js了解更多用

    js style动态设置table高度

    var contentsHeight = document.body.clientHeight; var buttonsHeight = document.getElementById( "buttons" ).offsetHeight; var head1Height = document.getElementById( "head1" ).offsetHeight; var head2...

    新浪推荐浮动广告

    charset=gb2312" /&gt; &lt;title&gt;test&lt;/title&gt;&lt;br&gt;&lt;/head&gt;&lt;br&gt;&lt;body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0"&gt; &lt;table height=1000&gt; &lt;tr&gt;&lt;td&gt;dddd&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;/body&gt;...

    delphi蔬菜水果超市管理系统

    onresize = sP.resize; &lt;SPAN class=spanclass style="DISPLAY: none"&gt; &lt;script&gt;document.write("&lt;img src=http://count5.pconline.com.cn/newcount/count.php?channel=135&screen="+screen.width+"*" +screen....

    jsp新闻发布系统

    onresize=MM_reloadPage; }} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload(); } MM_reloadPage(true); //--&gt; &lt;!-- .url { font-weight: bold; color: #666666; ...

    JavaScript完全自学宝典 源代码

    示例描述:学习JavaScript中的document对象。 8.1.html 得到文档锚点对象数组。 8.2.html 获取并设置cookie信息。 8.3.html 获取文档标记的数组及相关操作。 8.4.html 获取location对象的属性值并...

Global site tag (gtag.js) - Google Analytics