比如  <div class="hello">
     <div class="open"><img src="../pictrues/hello.png"></div>
  </div> 
当点击div hello时怎样取出img的src 来我用的方法是
 $(this).children("open").children("img").attr("src");这样取出的是undifine,希望大家帮忙

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    <script>
    $(document).ready(function() {
    alert($("div[@class=hello] div[@class=open] img").attr("src")); 
    });
    </script>
    </head>
    <body>
    <div class="hello">
    <div class="open"><img src="../pictrues/hello.png"></div>
    </div> 
    </body>
    </html>
      

  2.   


    $(".hello .open img").attr("src")
      

  3.   

    你的方式可以去呀,你自己写错了,$(this).children("open").children("img").attr("src");---- open是clss,前面要加点号的
      

  4.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
    <script type="text/javascript" src="jquery-1.2.1.js"></script>
    <script type="text/javascript">
      $(document).ready(function(){
      $(".hello").click(function(){
         var sr = $(".hello .open img").attr("src");
     alert(sr);
      });
      });
    </script> </HEAD> <BODY>
     <div class="hello" style="width:200px;height:100px;background:red">
         <div class="open"><img src="http://c.csdn.net/bbs/t/5/i/pic_logo.gif"></div>
      </div> 
     </BODY>
    </HTML>
      

  5.   

    javascript写的时候一定要细心。。
      

  6.   

    $(this).children(".open").children("img").attr("src"); 楼主少了一个点
      

  7.   

    还可以这样:<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script src="js/jquery-1.3.2.min.js"></script>
    </head>
    <body>
     <div class="hello">
         <div class="open"><img src="image/24k.gif"></div>
      </div> 
    <strong></strong>
    </body>
    <script language="javascript">
    $(function()
    {
      $('div.hello').click(function()
    {
      alert("图片路径是:"+$('div.hello').find("img")[0].src);
    });
    });
    </script>
    </html>