1

如何在最后一个 img 之后附加以下 html:

//create the icon
$('div.lookup-image-wrapper > div img').append('<div class="icon"></div>'); 

这是我的标记:

<div class="lookup-image-wrapper" style="text-align: center">

        <div class="divProductPic" id="divProductPic26039">
            <img alt="200 D" border="0" id="ProductPic26039" name=
            "ProductPic26039" onclick="popuplarge_26039()" src=
            "images/Product/medium/26039.jpg" style=
            "cursor:hand;cursor:pointer;" title=
            "Click here to view larger image">
        </div>


    <img alt="Show Picture 1" border="0" class="image-nav" onclick="_(1);" src="images/PRODUCT/icon/26039_1_.jpg"
        style="cursor:hand;cursor:pointer;">
    <img alt="Show Picture 2" border="0" class="image-nav" onclick="_(2);" src="images/PRODUCT/icon/26039_2_.jpg"
         style="cursor:hand;cursor:pointer;"><img alt="Show Picture 3" border="0" class="image-nav" onclick="setcolorpicidx_26039(3);" src=
        "images/PRODUCT/icon/26039_3_.jpg" style="cursor:hand;cursor:pointer;">

            <!--[#### THE DIV ICON NEEDS TO GO HERE #####]-->

     <div id="prodEmbiggen">
        <a href="javascript:void(0);" onclick=""><img align="absmiddle" alt="" border="0" src="showlarger.gif" title=
          "Click for larger image"></a>
     </div>
</div>
4

2 回答 2

3

试试这个:

$('div.lookup-image-wrapper > img:last').after('<div class="icon"></div>'); 
于 2012-08-09T09:14:11.260 回答
2

要在最后一张图片之后附加内容,请使用最后一个选择器 (:last)

$('div.lookup-image-wrapper > div img:last').append("your content");

如果你有很多内容要附加,你可以在这里缩小 HTML http://www.willpeavy.com/minifier/

于 2012-08-09T09:15:31.993 回答