飞比寻常 (JOE) 生,简单,活,简单,生活,不简单!
JOE个人网站
JOE个人网站,不仅仅是一个网站,更像是一个展现自我的平台,致力于让朋友们都可以
有所感触,有所收获。
3、阻止冒泡 在嵌套的对象中设置event,调用event中的cancelBubble来阻止冒泡 event.cancelBubble=true; //阻止冒泡 ----------------------------------------------------- <script type="text/javascript" charset="utf-8"> function test1() { alert('我来自大div'); } function test2() { event.cancelBubble=true; //阻止冒泡 alert('我来自小div'); } </script> </head> <body> <div onclick='test1()' style="width:300px;height:300px;background:green;"> <div onclick='test2()' style="width:100px;height:100px;background:red"></div> </div> </body> ------------------------------------------------------- 4、JS 在分帧中的使用 注意:将代码放在服务器端测试,不然会出现一些未知错误; ------------------方法1--------------- <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Top</title> <script type="text/javascript" charset="utf-8"> window.onload=function() { objs=window.top.frames; //这里的window代表top.html,这里的top指框架的顶层,而不是窗口top,即进入上层框架的意思 } function change() { //document.body.style.background='red'; //document.bgColor='red'; //通过frames获取全局窗口对象 //objs[0].document.bgColor='red'; //objs[0]相当于window objs[1].document.bgColor='green'; objs[2].document.bgColor='red'; /* 还可以直接指向具体的某一个窗体 var obj=window.top.right; obj.document.bgColor='green'; */ } function wu() { objs[1].document.bgColor='white'; objs[2].document.bgColor='white'; } </script> </head> <body> top <button onclick='change()'>点我</button> <button onclick='wu()'>去色</button> </body> </html> ------------方法2-------------------------------- <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Top</title> <script> window.onload=function() { oleft=window.top.left; oright=window.top.right; } function user() { oleft.location='./user/left.html'; oright.location='./user/right.html'; } function wenzhang() { oleft.location='./wenzhang/left.html'; oright.location='./wenzhang/right.html'; } </script> </head> <body> <h1>后台管理系统</h1> <div> <a href='javascript:user()'>用户管理</a> <a href='javascript:wenzhang()'>文章管理</a> </div> </body> </html> ==============================================================