我有下面的一組克隆和遞增編號jQuery中
<div id="question[1]" class="questions">
<p> Question: </p>
<input type="text" id="quizQuestion[1]" name="quizQuestion[1]" placeholder=" Question">
<input type="text" id="quizAnswer[1][1]" name="quizAnswer[1][1]" placeholder=" First Answer">
<input type="text" id="quizAnswer[1][2]" name="quizAnswer[1][2]" placeholder=" Second Answer">
<input type="text" id="quizAnswer[1][3]" name="quizAnswer[1][3]" placeholder=" Third Answer">
<input type="text" id="quizAnswer[1][4]" name="quizAnswer[1][4]" placeholder=" Fourth Answer">
</div>
我想要的1變成2 ...等
我雖然在形式再現每一個元素,但有必須是更好的方式呢?
// last id is found using regex (search for the only number in the id)
function createQuestion(lastId){
id = lastId + 1;
$('<div>').attr({
id: 'question[id]',
name: 'bar'
}).appendTo('form');
// create the rest of the inputs here (and added inside the created div)
}