js 獲取屬性名稱,再根據這個屬性名獲取值


 if (result.success) {
                        var obj = JSON.parse(result.data);
                        var sltObj = document.getElementById("selUser"); //獲取select對象
                        for (var i = 0; i < obj.length; i++) {
                            var optionObj = document.createElement("option"); //創建option對象
                            optionObj.value = Object.keys(obj[i]); //獲取屬性名稱
                            optionObj.innerHTML = obj[i][Object.keys(obj[i])];//獲取屬性名稱的值
                            sltObj.appendChild(optionObj);  //添加到select
                        }
                        console.log(result.data);
                    }
                    else {
                        layer.msg(result.data);
               var sltObj = document.getElementById("selUser"); //獲取select對象
               sltObj.options.length = 0;
                    }

 

              for(variable  in test001){   //variable 為屬性名
                    console.log(variable)   //name age
                }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM