js也是面向对象编程的。但是,它这个oop感觉不那么严谨,可又很新鲜。函数也可以是对象。今天的收获。用源生js编写成类似jq的用法。代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js入门基础</title>
</head>
<body>
<form name="form" action="" method="" onsubmit="return check();">
<input name="title" value=""/>
<input type="button" value="在早晨" id="button"/>
<input type="submit" value="在夜晚" id="button4"/>
<div id="txt"></div>
</form>
<script type="text/javascript">

function $(id)
 {
  obj = new Object();
  obj.ob = document.getElementById(id.split('#')[1]); 
  obj.click = function(fun)
  {
   obj.ob.onclick = fun;
  }
  return obj;
 }

$("#button").click(function(){alert('ok');});
$("#button4").click(function(){alert('okokokokok');});
</script>
</body>
</html>