2016-03-17 52 views
0

我正在開發一個使用此代碼的多語言網站,我得到它的工作完美,但我有問題,當它改變時,文本中的所有樣式都丟失,頂部菜單不是隻有失去它的風格,但它也完全停止工作多語言丟失的文本樣式

這是JavaScript函數,改變文本:

(function() { 
$.MultiLanguage = function(a, c) { 
    var b = this; 
    if (c == null) { 
     c = null 
    } 
    return $.getJSON(a, function(g) { 
     var f, d, h, e; 
     if (c !== null) { 
      localStorage.MultiLanguage = c 
     } else { 
      if (typeof localStorage.MultiLanguage === "undefined") { 
       c = localStorage.MultiLanguage = g.config["default"] 
      } else { 
       c = localStorage.MultiLanguage 
      } 
     } 
     d = g.language[c]; 
     e = []; 
     for (f in d) { 
      h = d[f]; 
      if ($(f).get(0).tagName.toLowerCase() === "title") { 
       document.title = h; 
       continue 
      } 
      if (f.length > 0) { 
       e.push($(f).html(d[f])) 
      } else { 
       e.push(void 0) 
      } 
     } 
     return e 
    }) 
} 
}) 
.call(this); 

的JSON語言文件是這樣的:

{ 
"config": { 
    "default": "es" 
}, 
"language": { 
    "es": {   
     "#ml-home": "HOME", 
     "#ml-agencia": "AGENCIA", 
     "ml-img-serv":"images/labels/servicios.png", 
     "#ml-texto_agencia": "Somos una agencia creativa y multidisciplinaria que busca potenciar a sus clientes. " 
    }, 
    "en": { 
     "#ml-home": "HOME", 
     "#ml-agencia": "AGENCY", 
     "ml-img-serv":"images/labels/agencia.png",  
     "#ml-texto_agencia": "Octagon is a creative and multidisciplinary agency seeking to empower its customers. " 
    } 
} 
} 
+0

什麼說控制檯?任何錯誤? –

+0

請注意,JSON的''ml-img-serv「'缺少''''或'#'選擇器中的任何一個。 –

+0

你有沒有jQuery功能?並關於你如何使用/調用它? –

回答

0

我發現它爲什麼會丟失樣式,函數會替換HTML中的所有內容,即使樣式不正確,也會替換類的樣式。我修好了它,它工作正常。