今天做了毕设的登录界面,使用了miniui框架,刚接触不好学。
数据的校验是使用了miniui的form校验文档,然后根据自己的需求进行修改。
其中主要贴一下搜了半天的单选按钮的使用:(学习miniui时主要看api文档才能少走弯路)
<tr>
<td>
<label for="role$text">角色:</label>
</td>
<td>
<input name="role" errorMode="none" onvalidation="onRoleValidation" class="mini-radiobuttonlist" required="true" valueField="value" repeatLayout="table"
label="角色" textField="name" data="[{name:'普通用户',value:0},{name:'管理员',value:1}]" requiredErrorText="角色不能为空"
/>
</td>
<td id="role_error" class="errorText"></td>
</tr>
对于登录功能,主要是请求了静态文件的内容,对于前台登录界面数据无要求,只是为了梳理逻辑
$.ajax({
url: "../data/login.json",
type: "get",
dataType: "json",
data: json,
success: function (result) { //成功操作
console.log(result);
if(result.flag){//登陆成功。根据身份跳转页面
if(data.role==0){
//html页面之间传值sessionStorage,只能传字符串格式
sessionStorage.setItem('user',mini.encode(result.data));
//页面跳转
window.location.href = './Userindex.html';
// console.log("跳转到普通用户页面")
}else if(data.role==1){
console.log("跳转到管理员页面")
}
}
},
error: function () {
console.log("发送数据失败");
}
})
html界面的传值:(关闭窗口则值消失)
//html页面之间传值sessionStorage,只能传字符串格式
sessionStorage.setItem('user',mini.encode(result.data));
接收值:
//直接获取的也是json字符串,需要转成对象
var data= sessionStorage.getItem("user");
console.log(mini.decode(data))
页面跳转:window.location.href = './Userindex.html';