我需要打上id,然后在 like后添加一个编号:id1
、id2
等。 每当你打上衣帽子之后,就把衣帽子 after上。
$("button").click(function() {
$("#id").clone().after("#id");
});
我需要打上id,然后在 like后添加一个编号:id1
、id2
等。 每当你打上衣帽子之后,就把衣帽子 after上。
$("button").click(function() {
$("#id").clone().after("#id");
});
$( #cloneDiv ).click(function(){
// get the last DIV which ID starts with ^= "klon"
var $div = $( div[id^="klon"]:last );
// Read the Number from that DIV s ID (i.e: 3 from "klon3")
// And increment that number by 1
var num = parseInt( $div.prop("id").match(/d+/g), 10 ) +1;
// Clone it and assign the new ID (i.e: from num 4 to ID "klon4")
var $klon = $div.clone().prop( id , klon +num );
// Finally insert $klon wherever you want
$div.after( $klon.text( klon +num) );
});
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<button id="cloneDiv">CLICK TO CLONE</button>
<div id="klon1">klon1</div>
<div id="klon2">klon2</div>
你们有许多带有诸如<代码>klon--5等身份识别器的内容,但斜体(不是按顺序排列)。 这里我们cannot上:last
或:first
,因此,我们需要一个机制检索最高级的ID:
const all = document.querySelectorAll( [id^="klon--"] );
const maxID = Math.max.apply(Math, [...all].map(el => +el.id.match(/d+$/g)[0]));
const nextId = maxID + 1;
console.log(`New ID is: ${nextId}`);
<div id="klon--12">12</div>
<div id="klon--34">34</div>
<div id="klon--8">8</div>
<>Update:
http://www.ohchr.org。
var cloneCount = 1;;
$("button").click(function(){
$( #id )
.clone()
.attr( id , id + cloneCount++)
.insertAfter( [id^=id]:last )
// ^-- Use #id if you want to insert the cloned
// element in the beginning
.text( Cloned + (cloneCount-1)); //<--For DEMO
});
Try,
$("#id").clone().attr( id , id1 ).after("#id");
如果你想要自动柜台,请见下文。
var cloneCount = 1;
$("button").click(function(){
$("#id").clone().attr( id , id + cloneCount++).insertAfter("#id");
});
这是我最简单的解决办法。
$( #your_modal_id ).clone().prop("id", "new_modal_id").appendTo("target_container");
工作进展
var i = 1;
$( button ).click(function() {
$( #red ).clone().appendTo( #test ).prop( id , red + i);
i++;
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<div id="test">
<button>Clone</button>
<div class="red" id="red">
</div>
</div>
<style>
.red {
width:20px;
height:20px;
background-color: red;
margin: 10px;
}
</style>
我制定了普遍的解决办法。 以下功能将改变ids子和 clo子名称。 在多数情况下,你需要一字不提地添加“数据-增长”的字面。
function renameCloneIdsAndNames( objClone ) {
if( !objClone.attr( data-row-id ) ) {
console.error( Cloned object must have data-row-id attribute. );
}
if( objClone.attr( id ) ) {
objClone.attr( id , objClone.attr( id ).replace( /d+$/, function( strId ) { return parseInt( strId ) + 1; } ) );
}
objClone.attr( data-row-id , objClone.attr( data-row-id ).replace( /d+$/, function( strId ) { return parseInt( strId ) + 1; } ) );
objClone.find( [id] ).each( function() {
var strNewId = $( this ).attr( id ).replace( /d+$/, function( strId ) { return parseInt( strId ) + 1; } );
$( this ).attr( id , strNewId );
if( $( this ).attr( name ) ) {
var strNewName = $( this ).attr( name ).replace( /[d+]/g, function( strName ) {
strName = strName.replace( /[[] ]+/g, );
var intNumber = parseInt( strName ) + 1;
return [ + intNumber + ]
} );
$( this ).attr( name , strNewName );
}
});
return objClone;
}
$( #cloneDiv ).click(function(){
// get the last DIV which ID starts with ^= "klon"
var $div = $( div[id^="klon"]:last );
// Read the Number from that DIV s ID (i.e: 3 from "klon3")
// And increment that number by 1
var num = parseInt( $div.prop("id").match(/d+/g), 10 ) +1;
// Clone it and assign the new ID (i.e: from num 4 to ID "klon4")
var $klon = $div.clone().prop( id , klon +num );
// Finally insert $klon wherever you want
$div.after( $klon.text( klon +num) );
});
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...
I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.