-9

我有这样的代码

<div id="product_images_54695_update" class="image-border float-left center cm-reload-54695">
<div class="cm-image-wrap"> 
    <span id="box_det_img_link_54695526fb066709b3_17149" class=" larger-image-wrap center">
        <a id="det_img_link_54695526fb066709b3_17149" class="cm-image-previewer cm-previewer" title="" href="/images/detailed/17/p54695_6768912_fotoapparat_olympus_pen_e_pm2_14_42_mm_kit_flash_a.jpg" rev="preview[product_images_54695526fb066709b3]" rel="preview[product_images_54695526fb066709b3]">
            <img id="det_img_54695526fb066709b3_17149" class=" " border="0" width="200" height="200" title="" alt="" src="/images/thumbnails/17/200/200/p54695_6768912_fotoapparat_olympus_pen_e_pm2_14_42_mm_kit_flash_a.jpg">
        </a>
    </span> 
</div>

我想在 js 中将这一行作为文本:

<img id="det_img_54695526fb066709b3_17149" class=" " border="0" width="200" height="200" title="" alt="" src="/images/thumbnails/17/200/200/p54695_6768912_fotoapparat_olympus_pen_e_pm2_14_42_mm_kit_flash_a.jpg">

我可以用 jquery 或本机 javascript 做到这一点吗?

4

3 回答 3

2

If that is content in the DOM, then select by ID, and use .outerHTML.

document.getElementById("det_img_54695526fb066709b3_17149").outerHTML;

Or select its parent and use .innerHTML. This assumes the parent has only the one child.

document.getElementById("det_img_link_54695526fb066709b3_17149").innerHTML;
于 2013-10-29T13:51:49.900 回答
0

您可以使用

$("#det_img_link_54695526fb066709b3_17149").html();
于 2013-10-29T13:56:02.280 回答
0

如果你知道idimg 的,那么你可以这样做:

$('<div/>').append($('#det_img_54695526fb066709b3_17149').clone()).html();

...否则,您可以尝试.cm-image-wrap进一步使用该类:

$('<div/>').append($('.cm-image-wrap img').clone()).html();
于 2013-10-29T13:50:57.927 回答