请告知如何使jquery下面克隆整行,此时只插入“3”。
我想插入以下内容,例如
<div class="servline_vhc servline_vhc_inspection clearfix">3</div>
jquery的:
var $clone = $('div.servline_vhc.servline_vhc_inspection.clearfix').last().clone(true);
$clone.insertAfter($('div.servline_vhc.servline_vhc_inspection.clearfix').last());
HTML:
<div class="servline_vhc servline_vhc_inspection clearfix">1</div>
<div class="servline_vhc servline_vhc_inspection clearfix">2</div>
<div class="servline_vhc servline_vhc_inspection clearfix">3</div>
答案 0 :(得分:0)
如果我理解了你想要的,请在下面的工作示例中查看控制台:
$(document).ready(function(){
// Setting the clone
var $clone = $('div.servline_vhc.servline_vhc_inspection.clearfix').last().clone(true);
// This already saves the last element node like you want
$clone.insertAfter($('div.servline_vhc.servline_vhc_inspection.clearfix').last());
// Check the console, that's the element DOM node HTML
console.log($clone[0]);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="servline_vhc servline_vhc_inspection clearfix">1</div>
<div class="servline_vhc servline_vhc_inspection clearfix">2</div>
<div class="servline_vhc servline_vhc_inspection clearfix">3</div>
如果你只想要这个元素,请提醒一下“.insertAfter()”的用法。
来自jQuery官方文档的一些链接: