我有以下 HTML:
<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>
轻松找到's 的文本值: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>
'stitle
和src
属性?如上面的代码所示,当前代码将它们返回为undefined
. 提前致谢!