不能少了DOCTYPE,浏覽器根據你申明的DOCTYPE決定頁面渲染規則,如果不聲明,不同的浏覽器顯示效果可能不一樣。
一個簡單的例子:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>示范</title>
<meta name="keywords" content="test,示范" />
<link rel="Stylesheet" type="text/css" href="common.css" />
<style type="text/css">
.test{border
:1px solid #ff0000;}
.dom{width:200px;height:100px;}
.notdom{width:202px;height:102px;}
</style>
</head>
<body>
<div id="main" class="test"></div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function(){
if($.support.boxModel){
$("#main").addClass("dom");
}else{
$("
#main").addClass("notdom");
}
});
</script>
</body>
</html>