我创建了一个逐步的过程,最终将形成一个测试。它从 Wordpress 中抓取数据行,每一行都是一个问题。
我想在最后添加一个额外的步骤,作为查看您的答案页面。在当前的最后一步中,它显示了一个提交按钮。
如何更改当前的最后一步以显示隐藏最后一个 .form-row div 并显示另一个带有提交按钮的 div 的下一步按钮?
也许是因为我已经盯着它看了很长时间,但是有人可以帮我解决这个问题吗?
到目前为止,这是我的代码:
<script type="text/javascript">
jQuery(function($) {
$(document).ready(function() {
// prepend a 'previous' button to all form-rows except the first
$('<button>').addClass('previous').appendTo($('.inner').not(':first'));
// hide all form-rows, but not the first one
$('.form-row').not(':first').hide();
// hide on last step
$('button.next').last().hide();
// add the submit button to the last form-row
$('<input>').addClass('submit').prop('type', 'submit').val('Submit').appendTo($('.form-row:last'));
// handle the previous button, we need to use 'on' here as the
// previous buttons don't exist in the dom at page load
$('.form-row').on('click', 'button.previous', function(e) {
e.preventDefault();
$(this).parents('div.form-row').hide().prev('div.form-row').show();
});
$('button.next').click(function(e) {
// prevent the next buttons from submitting the form
e.preventDefault();
// hide this form-row, and show the next one
$(this).parents('div.form-row').hide().next('div.form-row').show();
});
});
});
</script>
HTML:
<?php $counter = 1; if(get_field('step_by_step_test')): ?>
<?php while(the_repeater_field('step_by_step_test')): ?>
<div class="form-row">
<h2 style="float:left;margin-left:7px;"><?php the_title(); ?></h2>
<h2 style="float:right;"><?php echo $counter; ?> of <?php echo $total; ?></h2>
<div class="clear"></div>
<div id="module-area" style="margin-top:0px!IMPORTANT;">
<div id="modules-top"></div>
<div id="modules-repeat">
<?php if(get_sub_field('test_image')): ?>
<?php while(has_sub_field('test_image')): ?>
<img class="training" src="<?php echo the_sub_field('image'); ?>" />
<?php endwhile; ?>
<?php endif; ?>
<br /><br />
<p class="training"><b><?php echo the_sub_field('question'); ?></b></p>
<?php if(get_sub_field('answer_options')): ?>
<?php while(has_sub_field('answer_options')): ?>
<p class="contact-form">
<input style="width: 20px;" type="checkbox" name="CheckboxGroup<?php echo $counter; ?>[]" value="<?php echo the_sub_field('answer'); ?>" />
<?php echo the_sub_field('answer'); ?>
</p>
<?php endwhile; ?>
<?php endif; ?>
<div class="inner"></div>
<button class="next"></button>
<div class="clear"></div>
</div>
<div style="margin-bottom:5px;" id="modules-bottom"></div>
</div>
</div>
<?php $counter++; endwhile; ?>
<?php endif; ?>