Create div on the fly in asp.net mvc/jquery/javascript
I am developing the online test application in asp.net mvc. Where I need the wizard. I found the code to create the wizard Here. But here are limited divs/para. I don't know how many questions containing in开发者_如何学运维 the single test. So it is necessary to create the div for each question on the fly. And as per requirement show them in wizard structure. Also need to know how to pass the List to jquery function so that it will automatically create all these divs on the fly. Please help.
Maybe something like jquery UI accordion could help?
Working perfect for me. For Back button use parameter loadNext(i,iPrevious).
<script type="text/javascript">
$(function() {
var count = 6
for (i = 1; i <= count; i++) {
if(i < count) {
var iNext = i + 1;
var iPrevious = i - 1;
$("<div id=" + i + "> Step " + i +
"<button type='submit' onclick=" + "loadnext(" + i + "," + iNext + ");> Next" + "</button>" +
"</div>").hide().appendTo("#parentDiv").fadeIn();
}
else
if(i == count) {
$("<div id=" + i + "> Step " + i +
"<button type='submit' onclick=" + "loadnext();>Submit" + "</button>" +
"</div>").hide().appendTo("#parentDiv").fadeIn();
}
$("#" + i).hide();
}
});
$(function() { $("#1").show(); });
function loadnext(divout, divin) {
$("#" + divout).hide();
$("#" + divin).show();
}
</script>
<div id="parentDiv">
</div>
精彩评论