0

我正在创建一个双语网站,每种语言版本都存储在一个单独的目录中。然后我使用下面的 javascript 生成一个链接,该链接将在 URL 中查找语言目录并将其替换为另一个目录以在语言之间切换。

(function () {
  // this assumes you're on the en version and want to switch to chi
  var holder = document.createElement('div');
  var url = window.location.href.replace('/eng/', '/chi/');
  var link = document.createElement('a');

  link.innerText = '中文'; // or whatever the link should be
  link.href = url;
  holder.appendChild(link);
  document.write(holder.innerHTML);
})();

它在 Chrome 和 IE 中运行良好,但 Firefox 根本不显示链接。请帮忙!

4

1 回答 1

0

谢谢@AtesGoral 和@katspaugh!修改如下,现在可以使用

(function () {
  // this assumes you're on the en version and want to switch to chi
  var holder = document.createElement('div');
  var url = window.location.href.replace('/eng/', '/chi/');
  var link = document.createElement('a');

  link.textContent = '中文'; // or whatever the link should be
  link.href = url;
  holder.appendChild(link);
  document.write(holder.innerHTML);
})();
于 2013-02-15T08:36:39.243 回答