有这样一段html
 <div id = "testDiv">
        <button id="button1">button1</button>
        <button id="button2">button2</button>
        <button id="button3">button3</button>
    </div>
<div id="divMsg"></div>
    <button id = "testBtn">内容</button>我想在 $($("#testDiv").each).bind("click", function(event) {
         $("#divMsg").html(
               遍历时能够获取所有的子标签对象,然后分别操作           ); 
        }); 

解决方案 »

  1.   


    <div id = "testDiv">
      <button id="button1">button1</button>
      <button id="button2">button2</button>
      <button id="button3">button3</button>
      </div>
    <div id="divMsg"></div>
      <button id = "testBtn">内容</button>$("#testDiv").each(function() {
      $(this).bind('click', function(event){
          ......
      }); 
    );
      

  2.   

    我想在 $("#testDiv").bind("click", function(event) {
      $("#divMsg").html(
          // 绑定click以后,触发点击事件以后,这里this就是元素对象了
          this.id
      );  
      });  
      

  3.   

    $("#testDiv").each(function() {
      $(this).bind('click', function(event){
          ......
      }); 
      

  4.   

    直接用this (html element)
    如果需要jquery element就用$()包装一下
      

  5.   

    $("#testDiv button").each(function(i){
       $(this).bind("click",function(event){   });
    })
      

  6.   


    <!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>
        <title>Untitled Page</title>
        <style type="text/css">
        .even{background-color:gray;}
        .odd{background-color:white;}
        </style>
        <script type="text/javascript" src="jquery-1.4.4.js"></script>
        <script type="text/javascript">
            $(function() {
                $("#testDiv *").each(function(i) {
                    $(this).click(function() {
                        alert($(this).attr("id"));
                    });
                });
            });
        </script>
    </head>
    <body>
    <form >
    <div id = "testDiv">
      <button id="button1">button1</button>
      <button id="button2">button2</button>
      <button id="button3">button3</button>
      </div>
    <div id="divMsg"></div>
      <button id = "testBtn">内容</button>
      <p>
        我想在 $($("#testDiv").each).bind("click", function(event) {
          $("#divMsg").html(
          遍历时能够获取所有的子标签对象,然后分别操作 ); 
          });
      </p>
    </form>
    </body>
    </html>