关于如何html如何读取后台缓存数据

来源:互联网 发布:python 元组添加元素 编辑:程序博客网 时间:2024/06/05 13:22

/* 小白做笔记 */

var sp = new SharedPreference(); var user = sp.getJSON(skyi.key.user, null); //user是后台封装好的,相当于类之类的,里面含有你所需要的数据,读取出来//使用后台缓存数据

$("#userName").val(user.loginName) //userName是页面上对应的字段id,loginName是user里面的对应userName数据的名称

$("#sex > option").eq(user.detail.sex - 1).attr("selected","selected") // 性别下拉选择 option是下拉选项,因为sex的值是1和2,option的值是0和1,所以需要-1,sex在user里面的detail下面,所以需要user.detail。"selected","selected"前面一个selected是键,后面一个selected是值。attr()方法是获取属性的值//读取后台数据的头像

var imgSrc;

if(isNull(user.photo)) { //没有头像使用默认头像

imgSrc = "../../img/def_user.png";

} else { //头像路径格式:http://ip:port/userPhoto/skyi/filename.jpg

imgSrc = "http://" + skyi.ip + ":" + skyi.port + "/userPhoto/" + user.photo;

}

$("#touxiang").attr("src", imgSrc);console.log(user) // 这个可以读出user里面的值。可以根据需要取出来

0 1
原创粉丝点击