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