Youngger9765 commited on
Commit
982f0fe
·
1 Parent(s): 38ab2ef

更新 index.html 模板,改進表單模式下的 JSON 載入功能

Browse files

- 在表單模式中,新增從 JSON 載入變數的邏輯,並加入錯誤處理以提升穩定性
- 確保在載入過程中能正確處理解析錯誤,並在控制台顯示錯誤訊息

此次更新旨在增強用戶體驗,使用戶能夠更可靠地從本地儲存中載入變數設定。

Files changed (1) hide show
  1. templates/index.html +11 -1
templates/index.html CHANGED
@@ -2300,7 +2300,17 @@
2300
 
2301
  // If in form mode, update form from JSON
2302
  if (variableMode === 'form') {
2303
- updateFormFromJson();
 
 
 
 
 
 
 
 
 
 
2304
  }
2305
 
2306
  console.log('已從 localStorage 載入變數');
 
2300
 
2301
  // If in form mode, update form from JSON
2302
  if (variableMode === 'form') {
2303
+ try {
2304
+ const jsonData = JSON.parse(savedVariables);
2305
+ Object.keys(jsonData).forEach(key => {
2306
+ const element = document.getElementById(`var-${key}`);
2307
+ if (element) {
2308
+ element.value = jsonData[key] || '';
2309
+ }
2310
+ });
2311
+ } catch (e) {
2312
+ console.error('Error parsing saved JSON:', e);
2313
+ }
2314
  }
2315
 
2316
  console.log('已從 localStorage 載入變數');