我正在尝试创建一个 3 步流程,其中有人通过复选框在第 1 步和第 2 步中选择他们想要的项目,然后在第三步中显示这些选择的摘要。
这就是我的 html 的设置方式:
<form id="customisesystem" method="post" action="">
<div id="first-step">
<div class="steps">
<p><b>Step 1 of 3</b></p>
</div>
<div class="progress-buttons"></div>
<div class="clear"></div>
<div id="customise-area">
<div id="customise-title">
<p><b>1. Hardware & software options</b> <span>Please choose one or more of the following</span></p>
</div>
<div id="customise-area">
<?php $posts = get_field('options');
if( $posts ):
$items = 0;
foreach( $posts as $post): // variable must be called $post (IMPORTANT)
setup_postdata($post); ?>
<div class="custom-option">
<p><b>
<?php the_title(); ?>
</b></p>
<br />
<div> <?php echo the_content(); ?> </div>
<?php $counter = 1; while(the_repeater_field('images')): ?>
<?php if($counter <= 1) { ?>
<img width="180" height="136" src="<?php the_sub_field('image'); ?>" alt="<?php the_title(); ?>" />
<?php } ?>
<?php $counter++; endwhile; ?>
<p>
<input type="checkbox" name="hardware[]" value="<?php the_title(); ?>">
Select</p>
<div class="clear"></div>
</div>
<?php $items++; endforeach;
wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
endif; ?>
</div>
</div>
</div>
<!-- end first-step -->
<div id="second-step">
<div class="steps">
<p><b>Step 2 of 3</b></p>
</div>
<div class="progress-buttons"></div>
<div class="clear"></div>
<div id="customise-area">
<div id="customise-title">
<p><b>2. Accessories</b> <span>Please choose one or more of the following</span></p>
</div>
<div id="customise-area">
<?php $posts = get_field('accessories');
if( $posts ):
$items = 0;
foreach( $posts as $post): // variable must be called $post (IMPORTANT)
setup_postdata($post); ?>
<?php if ($items&1) { ?>
<div class="custom-option">
<p><b>
<?php the_title(); ?>
</b></p>
<br />
<div> <?php echo the_content(); ?> </div>
<?php $counter = 1; while(the_repeater_field('images')): ?>
<?php if($counter <= 1) { ?>
<img width="180" height="136" src="<?php the_sub_field('image'); ?>" alt="<?php the_title(); ?>" />
<?php } ?>
<?php $counter++; endwhile; ?>
<p>
<input type="checkbox" name="accessories[]" value="<?php the_title(); ?>">
Select</p>
<div class="clear"></div>
</div>
<?php } else { ?>
<div class="custom-option">
<p><b>
<?php the_title(); ?>
</b></p>
<br />
<div> <?php echo the_content(); ?> </div>
<?php $counter = 1; while(the_repeater_field('images')): ?>
<?php if($counter <= 1) { ?>
<img width="180" height="136" src="<?php the_sub_field('image'); ?>" alt="<?php the_title(); ?>" />
<?php } ?>
<?php $counter++; endwhile; ?>
<p>
<input type="checkbox" name="accessories[]" value="<?php the_title(); ?>">
Select</p>
<div class="clear"></div>
</div>
<?php } ?>
<?php $items++; endforeach;
wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
endif; ?>
</div>
</div>
</div>
<!-- end second-step -->
<div id="third-step">
<div class="steps">
<p><b>Step 3 of 3</b></p>
</div>
<div class="progress-buttons"></div>
<div class="clear"></div>
<div id="customise-area-3">
<p>Summary</p>
<div id="customise-area-3-child">
<input type="submit" name="submit" id="submit" value="submit" />
</div>
</div>
</div>
<!-- end third-step -->
</form>
这是我的 jquery 用于逐步完成该过程:
var prevLink = '<a class="back" href="#">Back</a>';
var nextLink = '</a><a class="next" href="#">Next</a>';
var navHTML = '<div class="prev-next">' +
prevLink +
nextLink +
'</div>';
var prevLink = '<a class="back" href="#">Back</a>';
var nextLink = '</a><a class="next" href="#">Next</a>';
var navHTML = '<div class="prev-next">' +
prevLink +
nextLink +
'</div>';
jQuery(document).ready(function( $ ) {
// init
$('#customisesystem > div')
.hide()
.prepend(navHTML);
$('#first-step .prev').remove();
$('#last-step .next').remove();
// show first step
$('#first-step').show();
$('a.next').click(function(){
var whichStep = $(this).parent().parent().attr('id');
if( whichStep == 'first-step' )
{
// validate first-step
}
else if( whichStep == 'second-step' )
{
// validate second-step
}
else if( whichStep == 'last-step' )
{
// validate last-step
}
$(this).parent().parent().hide().next().show();
});
$('a.back').click(function(){
var whichStep = $(this).parent().parent().attr('id');
if(whichStep == "first-step"){
$(".customise").hide();
$(".entire_product").show();
}
else{
$(this).parent().parent().hide().prev().show();
}
});
});
这是不起作用的部分:
jQuery(document).ready(function( $ )
{
var summary = $('#customise-area-3 p').get(0);
$('input[type=checkbox][name="hardware[]"]:checked').each(function(k,v) {
//Retrieve the value of the checkbox.
var checkboxValue = v.val();
//Add the checkbox value to the summary area:
summary[0].innerHTML += checkboxValue + '<br />';
});
});
目前,当我进行硬件选择并进入第三步时,它不会在摘要中显示任何信息。我哪里错了?
这是工作链接 - teamworksdesign.com/clients/rogue/system/dc-stimulator单击右侧的“获取报价”。这将显示第 1 步,单击下一步进入第 2 步,然后单击下一步进入第 3 步(即摘要)。