我有以下HTML:的jQuery找不到嵌套的圖像
<div id="showDropZone" class="ui-droppable" style="position: absolute; z-index: 1; outline-style: none; left: 0px; width: 379px; height: 500px;">
<div id="introText" style="display: none;">Drag and drop program images here</div>
<ul class="gallery ui-helper-reset">
<li class="imgThumbLi ui-draggable imageSelected" title="File Name: drago.jpg Dimension: 225x225 Size: 7 KB" style="display: list-item;">
<img class="image" src="/myApp/2012/5/1/1335900424140/39345e7f3d12487bb6e347e786194c9b" title="File Name: drago.jpg Dimension: 225x225 Size: 7 KB">
<div class="imageInfo">
<p class="detailTitle">Logo!</p>
</div>
</li>
</ul>
</div>
</div>
在我的jQuery/JS功能我得到<ul>
元素(及其<li>
孩子),我可以很容易地找到p.detailTitle
的文本值用下面的代碼:
$("#showDropZone").find("ul").each(function() {
$(this).find("li").each(function() {
var detailTitle = $(this).find("p.detailTitle").text();
// This prints "Logo!" correctly...
alert(detailTitle);
var imageTitle = $(this).find("img").title;
var imageSrc = $(this).find("img").src;
// But these both print "undefined"...
alert(imageTitle);
alert(imageSrc);
}
}
如何獲得<img>
的title
和src
屬性?如上面的代碼所示,當前的代碼將它們返回爲undefined
。提前致謝!