简体   繁体   English

如何更改Jquery克隆位置?

[英]How to change Jquery clone position?

i am created a dynamic clone html when click on plus icon. 单击加号图标时,我创建了一个动态克隆html。 it's work fine but problem is when i click on plus button clone place after plus button but i want to change the clone position before plus icon. 它工作正常,但问题是当我在加号按钮之后单击加号按钮克隆位置,但我想在加号图标之前更改克隆位置。

Here HTML Code 这里的HTML代码

<div class="table-responsive" style="max-height: 200px;">                                                                    
   <table class="" style="width: 100%;">
        <tbody id="attendCourse">                                                                        
             <tr id="attendCourse0">                                                                    
               <td style="width: 85%;">                                                  
                  <input name="course" class="form-control" type="text">                                                                                        
               </td>
               <td>
                 <img id="addAttand" src="<?php echo ASSETS_URL; ?>admin/images/plus1.png">
               </td>                                                                 
             </tr>

        </tbody>
    </table>
</div>

HTML Design Image HTML设计图片

在此处输入图片说明

Jquery Code jQuery代码

$(function() {
var $componentTB = $("#attendCourse"),
    $firstTRCopy = $("#attendCourse0").clone();
    $idVal = 1;

$("#addAttand").click(function() {
    var copy = $firstTRCopy.clone();         
    var newId = 'attendCourse' +$idVal;
    copy.attr('id', newId);
    $idVal += 1;
    copy.children('td').last().replaceWith("<td><div class=''><img onclick=\"remove('" + newId + "')\" src="+JS_SITEURL+"assets/admin/images/negative.png></div></td>");        
    $componentTB.append(copy);
});
});

使用jquery的insertbefore方法。

copy.insertBefore($("#attendCourse0"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM