Html、Javascript的笔记

来源:互联网 发布:大数据 涂子沛 pdf 编辑:程序博客网 时间:2024/06/01 15:04

1、Div层居中

<html>
<head>
<meta  http-equiv="Content-Type" content="text/html; charset=gb2312">
<title> ABC</title>
<SCRIPT>
<!--
window.onresize  resetDIV;  
function resetDIV(){  
  with(document.getElementsByTagName_r("DIV")[0].style)  
   
     left (document.body.offsetWidth-parseInt(width))/2  
     top (document.body.offsetHeight-parseInt(height))/2  
   }

}
//-->
</SCRIPT>
</head>
<body onload="resetDIV()">
<div style="position:absolute;width=200;height=200;background-color=yellow"></div>
</body>  
</html>

2. 兼容多浏览器的输入框的回车事件处理

function keydown(evt)
{
evt = (evt) ? evt : ((window.event)? window.event : "")
keyCode = evt.keyCode ? evt.keyCode: (evt.which ? evt.which : evt.charCode);
if (keyCode == 13) {
//处理代码
}
}
<input type="text"onkeydown=" keydown(event)" />
原创粉丝点击