![](/img/trans.png)
[英]JavaScript - Using jQuery find as matching variable, then doing something?
[英]javascript/jquery indicate something is a variable
我有一個將用戶數據注入html文件的功能
json格式是這樣的:
{"Fname":"abc","LName":"cdf", "Phone":"123456";}
這是將數據注入html文件的功能:
function injectData(data){
$.each(data, function(key, value) {
//notice that in the "data.value", I want 'value' to be a variable
//so that when I loop over the array, data.value will become data.Fname,
//and then data.LName and then data.Phone
$("#"+key).html(' ' + data.value +'');
});
如何在調用data.value之前強制javascript首先將“值”解釋為變量,以便從JSON對象獲取真實值? 這有點令人困惑。 希望你能理解。謝謝
寫類似:
for(key in data){ $("#"+key).html(' ' + data[key] +''); });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.