欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery將json轉(zhuǎn)為數(shù)據(jù)字典的實(shí)例代碼

 更新時(shí)間:2019年10月11日 09:17:00   作者:過客璇璇  
這篇文章主要介紹了jquery將json轉(zhuǎn)為數(shù)據(jù)字典的實(shí)例代碼,非常不錯,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1.基礎(chǔ)——定義json文件

{
 "userinfo": [
 { "account":"15639864589" , "password":"123456789" , "email":"123456789@qq.com" },
 { "account":"15652689689" , "password":"123456789" , "email":"123456789@qq.com" },
 { "account":"15635456989" , "password":"123456789" , "email":"123456789@qq.com" },
 { "account":"15632145689" , "password":"123456789" , "email":"123456789@qq.com" }
 ]
}

目錄如下:

2.ajax請求json jquery轉(zhuǎn)換為數(shù)據(jù)字典

我們通過ajax請求該json文件的數(shù)據(jù)  將其轉(zhuǎn)換為字典

//-----基礎(chǔ)信息start
//用戶信息字典
var userinfoDic = {};
$.ajax({
 //請求方式為get
 type:"GET",
 //json文件位置
 url:"./json/user.json",
 //返回?cái)?shù)據(jù)格式為json
 dataType: "json",
 //請求成功完成后要執(zhí)行的方法
 success: function(data){
 //使用$.each方法遍歷返回的數(shù)據(jù)date
 $.each(data.userinfo,function(i,item){
 //設(shè)置根據(jù)用戶賬號密碼找用戶
 userinfoDic[item.account,item.password] = item;
 });
 }
});
//-----基礎(chǔ)信息end

3.字典測試

//登錄按鈕的點(diǎn)擊事件
$("#login").bind('click',function(){
 var account = $("#account").val();
 var password = $("#password").val();
 //
 if(account != '' && password != ''){
  if(userinfoDic[account,password]){
  window.location.href = 'index.html';
  }else{
  alert("賬號或密碼錯誤!");
  }
 }else{
 alert("賬號或密碼不能為空!");
 }
  
});

4.測試截圖

總結(jié)

以上所述是小編給大家介紹的jquery將json轉(zhuǎn)為數(shù)據(jù)字典的實(shí)例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

最新評論