你可以这样做,它可以帮助你......
HTML
function show_ques() {
var i = $(this).attr('id').substr(-1);
if ($(this).is(":checked")) {
//get total count of question list
var nQue = $("#quelist").find("div[class^=que]").length;
var isSet = false; //boolean to check if que is appended or not.
if (nQue > 0) {
var nq = 0;
$("#quelist").find("div[class^=que]:last").attr('class').substr(-1);
$("#quelist").find("div[class^=que]").each(function() {
nq = $(this).attr('class').substr(-1);
if (nq > i && !isSet) {
$("#quelist .que" + nq).before("
isSet = true;
}
});
}
if (!isSet) {
$("#quelist").append("
}
} else {
$("#quelist").find("div.que" + i).remove();
}
}
$(function() {
$("#btnadd").click(function() {
var i = $("#quecheckbox").find("input[type=checkbox]").length;
if (i <= 0) i = 1;
else i += 1;
$("#quecheckbox").append("
$("#que" + i).bind('change', show_ques);
});
$("#btnreset").click(function() {
$("#quecheckbox").html("");
$("#quelist").html("");
});
});我在http://codebins.com/bin/4ldqpa8上为上述问题做过bin