亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用用戶輸入顯示 json 值

使用用戶輸入顯示 json 值

元芳怎么了 2023-11-12 15:24:37
我的服務器上有一個 json 腳本。我有三個文本字段。<label>Index</label><input type="text" id="index" /><br/><label>Worker#</label><input type="text" id="Worker_ID" /><br/><label>Worker Value</label><input type="text" id="worker_value" /><br/><button onclick="Fetch_Result()">Search</button>我有一個腳本可以顯示 json 文本的具體值<script>函數 Fetch_Result() {  var index = document.getElementById("index").value;  var Value = document.getElementById("Worker_ID").value;  var x = document.getElementById("worker_value").value;  var settings = {     "async": true,     "crossDomain": true,     "url": "http://www.hotel1.com/Experiment/Api/Json1.php",     "method": "GET"  }  $.ajax(settings).done(function (response) {     response = JSON.parse(response); // the change is here     //console.log(response);     console.log(response[index].x.ID);  });}{    "Worker1": {        "ID :": "1",        "Username": "Tony"    }這是我的 json 文本。我無法要求用戶在文本框中輸入工人編號。我想知道如何用文本框值替換 x 和 ID。這樣我就不必繼續為新工人編寫代碼。示例:console.log(response[index].userinput1.userinput2);userinput1 是 Worker 編號,例如:Worker1、Worker2、... userinput2 是 Worker 編號的值,例如:ID、用戶名、...有人能幫我嗎
查看完整描述

1 回答

?
米琪卡哇伊

TA貢獻1998條經驗 獲得超6個贊

我無法添加評論,因為我的分數低于 50。但你可以這樣做:

console.log(response[index][id])
console.log(response[index][username])


查看完整回答
反對 回復 2023-11-12
  • 1 回答
  • 0 關注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號