猿问

关于jquery的一个问题,很简单的,我不懂,求教育……

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function(){
  $("#up").click(function(){
    var afirst=$(".imglist a:first-child").html();
    alert(afirst);
  });
});
</script>
</head>
<body>
<a href="javascript:void(0);" id="up">往前走</a>


<div class="imglist">


<a href="javascript:void(0);" title='/UpLoadFiles/memberpic/2012071211033214.jpg'>
111
</a>


<a href="javascript:void(0);" title='/UpLoadFiles/memberpic/2012071211032801.jpg'>
222
</a>


<a href="javascript:void(0);" title='/UpLoadFiles/memberpic/2012071211031878.jpg'>
333
</a>
<a href="javascript:void(0);" title='/UpLoadFiles/memberpic/2012071208381331.jpg'>
444
</a>


<a href="javascript:void(0);" title='/UpLoadFiles/memberpic/2012071208380428.jpg'>
555
</a>


</div>


<a href="javascript:void(0);" id="next">往后走</a>
</body>
</html>

 

问题是,现在只能取到 111

我想取到 :<a href="javascript:void(0);" title='/UpLoadFiles/memberpic/2012071211033214.jpg'>
111
</a>

 

求同志们赐教……

喵喵时光机
浏览 335回答 5
5回答

GCT1015

$.extend($.prototype, { htmlCode:function(){ var div = $('<div></div>'); this.appendTo(div); return div.html(); } });   $('#id').htmlCode();

慕婉清6462132

 var afirst=$(".imglist:first-child").html();这样试试

达令说

返回null

胡说叔叔

@iisp: $(".imglist> a:first").html();

慕莱坞森

@荒野的呼唤: 返回111
随时随地看视频慕课网APP
我要回答