下面是如何顯示/隱藏一個例子:
http://jsfiddle.net/rVwkn/14/
的jQuery:
$('#stepbtn').click(function() {
if ($('#step2').is(':visible')) {
$('#step3').show();
$('#stepbtn').hide();
} else if ($('#step1').is(':visible')) {
$('#step2').show();
}
});
$('#backbtn').click(function() {
if ($('#step3').is(':visible')) {
$('#step3').hide();
$('#stepbtn').show();
} else if ($('#step1').is(':visible')) {
$('#step1').hide();
}
});
CSS:
#step2 {
display:none;
}
#step3 {
display:none;
}
#backbtn { display: none }
HTML:
<div id="step1">
<h3>Step 1</h3>
</div>
<div id="step2">
<h3>Step 2</h3>
</div>
<div id="step3">
<h3>Step 3</h3>
</div>
<button id="stepbtn">Next Step</button>
<button id="backbtn">Go Back a Step</button>
UPDATE:
這裏是另一個版本,以及,它給你更多的靈活性:
http://jsfiddle.net/ddr6D/6/
的jQuery:
$(document).ready(function() {
var current_step = 1;
var max_number_of_steps = 6;
$('#stepbtn').click(function() {
var next_step = current_step + 1;
$('#step'+next_step).slideDown();
$('#backbtn').show();
current_step++; // increase the step we are on...
if (current_step == max_number_of_steps) {
$('#stepbtn').hide();
}
});
$('#backbtn').click(function() {
$('#step'+current_step).slideUp();// hide it first,
current_step--; // now update, so we know the correct step we are on
if (current_step == 1) {
$('#backbtn').hide();
}
if (current_step < max_number_of_steps) {
$('#stepbtn').show(); // show, if its been hidden...
}
});
});
CSS:
#step2,#step3,#step4,#step5,#step6 {
display:none;
}
#backbtn { display: none }
HTML:
<div id="step1">
<h3>Step 1</h3>
</div>
<div id="step2">
<h3>Step 2</h3>
</div>
<div id="step3">
<h3>Step 3</h3>
</div>
<div id="step4">
<h3>Step 4</h3>
</div>
<div id="step5">
<h3>Step 5</h3>
</div>
<div id="step6">
<h3>Step 6</h3>
</div>
<button id="stepbtn">Next Step</button>
<button id="backbtn">Go Back a Step</button>
讓我怎麼隱藏我的第一步? – user3418336
您可以使用部分選擇器,如$('div [id^=「stepshow_」]') –
隱藏步驟如何?我如何定義隱藏步驟後點擊將隱藏所有? – user3418336