以前没注意过,认为jquery 中的 $("#air") 与 document.getElementById("air") 是一回事,指的是同一个东西。在今天写一个canvas的小程序时,才发现这两者是不一样的。
直接用alert()来显示这两个方法倒底获得的是什么。代码如下
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>air</title>
<link href="css/index.css" rel="stylesheet" type="text/css">
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
</head>
<body>
<div class="warp">
<canvas >
实际上,$("#air")[0]等同于 document.getElementById("air");