一个基于HTML与JavaScript的Wizard演示

整个过程模仿用户注册,分为三步完成,运行效果如下:


全部代码如下:

<html>
<head>
    <title>JavaScript Create User Wizard Example</title>
    <script type="text/javascript">
    	function handleWizardNext()
        {
            if (document.getElementById('ButtonNext').name == 'step2')
            {
            	document.getElementById('step1').style.display = 'none';
                document.getElementById('step2').style.display = '';
				document.getElementById('ButtonNext').name = 'step3';

                document.getElementById('ButtonPrevious').name = 'step1';
                document.getElementById('ButtonPrevious').disabled = '';

                document.getElementById('headstep1').style.backgroundColor = 'silver';
                document.getElementById('headstep2').style.backgroundColor = 'white';
            }
            else if(document.getElementById('ButtonNext').name == 'step3')
            {
            	document.getElementById('step2').style.display = 'none';
                document.getElementById('step3').style.display = '';

				document.getElementById('ButtonNext').name = '';
				document.getElementById('ButtonNext').disabled = 'disabled';

				document.getElementById('ButtonPrevious').name = 'step2';
                document.getElementById('ButtonPrevious').disabled = '';
				document.getElementById('SubmitFinal').disabled = '';

				document.getElementById('headstep2').style.backgroundColor = 'silver';
                document.getElementById('headstep3').style.backgroundColor = 'white';
            }

        }

        function handleWizardPre() {
        	// console.log("this is to go back previous page");
        	if (document.getElementById('ButtonPrevious').name == 'step1') {
        		// display/hide the relevative fieldset
        		document.getElementById('step2').style.display = 'none';
                document.getElementById('step1').style.display = '';

                // enable/disable buttons
				document.getElementById('ButtonNext').name = 'step2';
				document.getElementById('ButtonPrevious').name = '';
                document.getElementById('ButtonPrevious').disabled = 'disabled';
                document.getElementById('SubmitFinal').disabled = 'disabled';
                document.getElementById('SubmitFinal').name = '';

                // change navigation color
                document.getElementById('headstep2').style.backgroundColor = 'silver';
                document.getElementById('headstep1').style.backgroundColor = 'white';

        	} else if(document.getElementById('ButtonPrevious').name == 'step2') {
        		// display/hide the relevative fieldset
        		document.getElementById('step3').style.display = 'none';
                document.getElementById('step2').style.display = '';

                // enable/disable buttons
				document.getElementById('ButtonNext').name = 'step3';
				document.getElementById('ButtonNext').disabled = '';

				document.getElementById('ButtonPrevious').name = 'step1';
                document.getElementById('ButtonPrevious').disabled = '';
                
                document.getElementById('SubmitFinal').name = '';
                document.getElementById('SubmitFinal').disabled = 'disabled';

                // change navigation color
                document.getElementById('headstep3').style.backgroundColor = 'silver';
                document.getElementById('headstep2').style.backgroundColor = 'white';        		
        	}
        }
    </script>
    <style type="text/css">  
    	#userregisterizard {
    		width:500px;
    		height: 350px;
    		background-color:#EFEFEF;
    		border-style:solid;
			border-width:5px;
			border-color:#001111;
    	}
    	#userregisterizard #wizardpanel{  
            padding: 5px;  
            height: 250;  
        }
        #userregisterizard #buttons{  
            padding: 5px;  
            height: 40;  
        }
        #navigationbar {
        	padding: 2px; 
        	height: 50px;
        	background-color:silver;
        }  
    </style>
</head>
<body>
	<div id="userregisterizard">
		<div id="navigationbar">
			<label id="headstep1" style="background-color:white">Step 1: Register</label>
			<label id="headstep2" style="background-color:silver">Step 2: Detail Profile</label>
			<label id="headstep3" style="background-color:silver">Step 3: Finalize</label>
		</div>
		<div id="wizardpanel">
			<fieldset id="step1">
	  			<legend>Create User</legend>
				<label>Name<font color="red">*</font>:Enter your preferred user name</label><br>
				<input name="wsname" type="text"></br>
				<label>Password<font color="red">*</font>:Please use 8~16 characters that will protect your user account</label><br>
				<input name="uspassword" type="password"></br>
			</fieldset>

			<!-- edit yourself profile -->
			<fieldset id="step2" style="display:none">
				<legend>Edit Profile</legend>
				<label>Occupation<font color="red">*</font>:What do you do?</label><br>
				<input name="wsname" type="text"></br>
				<label>Company<font color="red">*</font>:Which company you are working for</label><br>
				<input name="company" type="text"></br>
				<label>Hometown<font color="red">*</font>:Where is you hometown</label><br>
				<input name="hometown" type="text"></br>
				<label>Mobilephone Number<font color="red">*</font>:Can we get your phone number?</label><br>
				<input name="phonenumber" type="text"></br>
			</fieldset>
			<fieldset id="step3" style="display:none">
	  			<legend>Welcome you</legend>
				<p>you can see the your user profile what you have entered.<p>
			</fieldset>
		</div>
		<div id="buttons">
			<input id="ButtonPrevious" type="button" value="Previous" disabled="disabled" name="" οnclick="handleWizardPre()"/>
			<input id="ButtonNext" type="button" value="Next" name="step2" οnclick="handleWizardNext()" />
			<input id="SubmitFinal" type="submit" value="Finish" disabled="disabled" />
		</div>
	</div>
</body>
</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WEUI 风格的 Wizard 控件是一个用于指引用户完成多步骤操作的 UI 组件。下面是一个简单的步骤: 1. 在 HTML 中创建一个包含多个步骤的 Wizard 容器: ```html <div class="weui-wizard"> <div class="weui-wizard__steps"> <div class="weui-wizard__step"></div> <div class="weui-wizard__step"></div> <div class="weui-wizard__step"></div> </div> <div class="weui-wizard__content"></div> </div> ``` 2. 在 CSS 中定义 Wizard 容器的样式: ```css .weui-wizard { display: flex; flex-direction: column; align-items: center; } .weui-wizard__steps { display: flex; justify-content: center; align-items: center; margin-bottom: 10px; } .weui-wizard__step { width: 20px; height: 20px; border-radius: 50%; background-color: #d8d8d8; margin-right: 10px; } .weui-wizard__step:last-child { margin-right: 0; } .weui-wizard__step--active { background-color: #07c160; } ``` 3. 在 JavaScript 中实现 Wizard 控件的逻辑: ```javascript var wizard = document.querySelector('.weui-wizard'); var steps = wizard.querySelectorAll('.weui-wizard__step'); var content = wizard.querySelector('.weui-wizard__content'); var currentStep = 0; function showStep(stepIndex) { if (stepIndex < 0 || stepIndex >= steps.length) { return; } currentStep = stepIndex; steps.forEach(function(step, index) { if (index < stepIndex) { step.classList.add('weui-wizard__step--active'); } else { step.classList.remove('weui-wizard__step--active'); } }); content.innerHTML = 'Step ' + (stepIndex + 1); } showStep(currentStep); document.querySelector('.weui-btn_primary').addEventListener('click', function() { showStep(currentStep + 1); }); document.querySelector('.weui-btn_warn').addEventListener('click', function() { showStep(currentStep - 1); }); ``` 这个示例代码实现了一个包含多个步骤的 Wizard 控件,用户可以通过点击“下一步”和“上一步”按钮来切换步骤。在 showStep 函数中,我们使用了 CSS 类来标识当前步骤。在用户点击“下一步”和“上一步”按钮时,我们调用 showStep 函数来更新当前步骤的状态。 这只是一个简单的示例,你可以根据自己的需求来扩展此控件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值