jQuery用img包装img

ark*_*eph 7 jquery

你好,如果类有锚,我试图用锚包装图像.

jQuery的:

if ( $(".views-row:has(a)").length) {
    var noderef = $(this).attr("anchor");
    $(".views-field-field-teaserbox-fid img").wrap("[anchor = "'+noderef+'" ]");
}
Run Code Online (Sandbox Code Playgroud)

HTML:

    <div class="view-content">
        <div class="views-row">

          <div class="views-field-field-node-ref-nid">
           <span class="field-content"><a class="active" href="/all-essentials-inspiring-events">All the essentials of inspiring events.</a></span>
         </div>

         <div class="views-field-field-teaserbox-fid">
            <span class="field-content"><img width="208" height="137" src="http://localhost:8888/sites/default/files/wedding_Giveaway_teaser.jpg?1283880578" alt="" class="imagefield imagefield-field_teaserbox"></span>
    </div>
Run Code Online (Sandbox Code Playgroud)

另外,我应该使用双引号还是单引号?

Sco*_*ott 11

这个怎么样?

$("img.anchor").wrap('<a href="#" />');
Run Code Online (Sandbox Code Playgroud)

参考:http: //api.jquery.com/wrap/