hao_2468

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
下面我们来看看jquery如何给 DOM 各个元素批量绑定事件
  1. <SCRIPT LANGUAGE="JavaScript">
  2. <!--
  3. $(document).ready(function() {
  4. $("div").click(function(){//$("div")就是页面中所有的 div标签
  5.    alert("Hello World!");
  6. })
  7. })
  8. //-->
  9. </SCRIPT>
复制代码
$("div").click $("div")就是页面中所有的 div标签 这句话就是给所有的标签为div的元素 绑定了一个click事件 即当所有div 被鼠标单击的时候 执行 alert("Hello World!");
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>jquery基础教程二(demo鼠标点击事件)</title>
  6. <script language="javascript" src="jquery.js"></script>
  7. <SCRIPT LANGUAGE="JavaScript">
  8. <!--
  9. $(document).ready(function() {
  10. $("div").click(function(){
  11.    alert("Hello World!");
  12. })
  13. })
  14. //-->
  15. </SCRIPT>
  16. </head>
  17. <body>
  18. <div>Hello World!</div>
  19. </body>
  20. </html>
posted on 2010-04-01 16:56  hao_2468  阅读(161)  评论(0编辑  收藏  举报