如何訪問課程imagecontainerbox
中的元素?我想訪問previewimage1
,previewimage2
和每一種這種類型的元素。我試過nth-child
但它不工作。它使我在預覽的元素列表DIV不是我想要的:如何訪問課堂中的所有元素?
$('.imagecontainerbox:nth-child(0) img').attr(src);
$('preview').children('.imagecontainerbox:nth-child(0) img').attr(src);
HTML:
<div id="preview" style="">
<span id="text0"></span>
<div id="previewimage1" class="imagecontainerbox" style="position:relative;padding:5px;margin:5px;width:515px;">
<img src="undefined" class="realimage" id="image1" height="undefined" width="undefined" style="position:relative ;z-index:2px; border:5px solid #f8f8f8;border-radius:5px;padding:2px;">
<img src="image/list/cancel1.png" style="float:right;padding:5px;position:absolute;top:10px;left:NaNpx;z-index: 1;" onclick="removeimage(this)">
</div>
<span id="text1"> </span>
<span id="text2"> </span>
<span id="text3"> </span>
<div id="previewimage4" class="imagecontainerbox" style="position:relative;padding:5px;margin:5px;width:515px;">
<img src="tempimage/MosLake1365324410.jpg" class="realimage" id="image4" height="666.66666666667" width="500" style="position:relative ;z-index:2px; border:5px solid #f8f8f8;border-radius:5px;padding:2px;">
<img src="image/list/cancel1.png" style="float:right;padding:5px;position:absolute;top:10px;left:490px;z-index: 1;" onclick="removeimage(this)">
</div>
<span id="text4"> </span>
<div id="previewimage5" class="imagecontainerbox" style="position:relative;padding:5px;margin:5px;width:515px;">
<img src="tempimage/MosLake1365324416.jpg" class="realimage" id="image5" height="375" width="500" style="position:relative ;z-index:2px; border:5px solid #f8f8f8;border-radius:5px;padding:2px;">
<img src="image/list/cancel1.png" style="float:right;padding:5px;position:absolute;top:10px;left:490px;z-index: 1;" onclick="removeimage(this)">
</div>
<span id="text5"> </span>
<div id="previewimage6" class="imagecontainerbox" style="position:relative;padding:5px;margin:5px;width:515px;">
<img src="tempimage/MosLake1365324421.jpg" class="realimage" id="image6" height="666.66666666667" width="500" style="position:relative ;z-index:2px; border:5px solid #f8f8f8;border-radius:5px;padding:2px;">
<img src="image/list/cancel1.png" style="float:right;padding:5px;position:absolute;top:10px;left:490px;z-index: 1;" onclick="removeimage(this)">
</div>
<span id="text6"> </span>
<div id="previewimage7" class="imagecontainerbox" style="position:relative;padding:5px;margin:5px;width:515px;">
<img src="tempimage/MosLake1365324426.jpg" class="realimage" id="image7" height="375" width="500" style="position:relative ;z-index:2px; border:5px solid #f8f8f8;border-radius:5px;padding:2px;">
<img src="image/list/cancel1.png" style="float:right;padding:5px;position:absolute;top:10px;left:490px;z-index: 1;" onclick="removeimage(this)">
</div>
<span id="text7"> </span>
<div id="previewimage8" class="imagecontainerbox" style="position:relative;padding:5px;margin:5px;width:515px;">
<img src="tempimage/MosLake1365324431.jpg" class="realimage" id="image8" height="666.66666666667" width="500" style="position:relative ;z-index:2px; border:5px solid #f8f8f8;border-radius:5px;padding:2px;">
<img src="image/list/cancel1.png" style="float:right;padding:5px;position:absolute;top:10px;left:490px;z-index: 1;" onclick="removeimage(this)">
</div>
<span id="text8"> </span>
<div id="previewimage9" class="imagecontainerbox" style="position:relative;padding:5px;margin:5px;width:515px;">
<img src="tempimage/MosLake1365324440.jpg" class="realimage" id="image9" height="666.66666666667" width="500" style="position:relative ;z-index:2px; border:5px solid #f8f8f8;border-radius:5px;padding:2px;">
<img src="image/list/cancel1.png" style="float:right;padding:5px;position:absolute;top:10px;left:490px;z-index: 1;" onclick="removeimage(this)">
</div>
<span id="text9"> asd</span>
</div>
我使用這個jQuery:
var image = $('#preview').children('.imagecontainerbox').length;
var imagesrc = $('#preview .imagecontainerbox:nth-child('+image+') img').attr('src');
for(var i = 1; i <= image; i++) {
if($(it).siblings('.realimage').attr('src') == $('.imagecontainerbox:nth-child('+i+') img').attr('src')) {
num = i;
var p = $('#preview').children('.imagecontainerbox:nth-child('+i+')').attr('id');
}
}
你想要*什麼?獲取'imagecontainerbox' div中圖像的所有'src'屬性? – Uby 2013-04-07 09:33:47
'src'未定義。如果你想使用'src'屬性的值'.attr(「src」)' – 2013-04-07 09:35:27
no ...我不想讓src ....我想要imagecontainer框的屬性「id」 .....意味着我已經把它取消的形象.... ewhen我按取消圖像....它應該取消整個div .... – 2013-04-07 09:36:02