JavaScript で解決するのが難しい問題がもう 1 つあります。以下に示すように、文字列変数はフォーム入力値の外側から取得されます
document.addEventListener('DOMContentLoaded', function() {
var Country = document.getElementById('countr').value;
}, false);
変更する必要がある文字列アドレスは、相対 href アドレスの一部であり、2 つの異なる形式を取ります。
モデル/世界/some_site.html
また
models/local/some_site.html
変数 Country も変更されます。たとえば、ドイツ語、イギリス、フランスなどです。
「世界」または「ローカル」を国変数に置き換えたい場合、私がする必要があるのは、そのようなことをすることです
var address = address.split('world').join(Country).split('local').join(Country);
また
var address = address.replace('world', new RegExp(Country, 'g')).replace('local', new RegExp(Country, 'g'));
結果は、たとえば次のようになります
モデル/ドイツ語/some_site.html
しかし、それは機能しません。理由はわかりません。どんな助けも私にとって非常に貴重です。
国変数が処理されたくないことがわかりました。なぜですか? このスクリプトは私の変数をまったく表示しません。
document.addEventListener('DOMContentLoaded', function() {
var Country = document.getElementById('cotr').value;
}, false);
document.write(Country);
したがって、この例もうまくいきません
address.replace(/(local|world)/,Country)
何か助けはありますか?
私の実際のコードは以下のようになります
Indeks.prototype.wyswietl = function(adres)
{
if (typeof adres == 'undefined') adres =
document.forms[this.id].elements['hasla'].value;
if (typeof this.ramka == 'string')
{
var okno =
window.open(adres, this.ramka, 'menubar=yes,toolbar=yes,location=yes,directories=no,status=yes,scrollbars=yes,resizable=yes');
if (okno) okno.focus();
else window.location.href = adres;
}
else this.ramka.location.href =
adres.replace(/(world|local)/,Country);//here I need replacement adres is address
}