Javascript 如何使用条件If和else修复onload函数
我这里的问题是,我不知道如何执行if语句。对于onload页面,我希望当id为#lang_link\[fr\]时直接运行函数ParseJSON1,当我的id为#lang_link\[en\]时运行函数ParseJSON2 我想解决这个问题:Javascript 如何使用条件If和else修复onload函数,javascript,html,jquery,json,Javascript,Html,Jquery,Json,我这里的问题是,我不知道如何执行if语句。对于onload页面,我希望当id为#lang_link\[fr\]时直接运行函数ParseJSON1,当我的id为#lang_link\[en\]时运行函数ParseJSON2 我想解决这个问题: window.onload = function runAtLoadTime() { if(document.getElementsById('#lang_link\\[fr\\]').value = 'fr' ){ ParseJSO
window.onload = function runAtLoadTime() {
if(document.getElementsById('#lang_link\\[fr\\]').value = 'fr' ){
ParseJSON1();
}
else
{
ParseJSON2();
}
}
致电:
$(document).ready(function (){
$('#lang_link\\[fr\\]').click(function (){
ParseJSON1('fr');
});
$('#lang_link\\[en\\]').click(function (){
ParseJSON2('en');
});
});
要运行的代码:
function ParseJSON1() {
var JSONObject = {
"footerboutiques": "Sourav french",
"boutiquelink": "https://www.w3schools.com/js/js_loop_for.asp",
"footerrestaurants": "Kayal",
"Restaurantslink": "https://www.w3schools.com/js/js_loop_for.asp",
"footeracces": 24,
"acceslink": "https://www.w3schools.com/js/js_loop_for.asp",
"footeraerogare": "123456" ,
"aerogarelink": "https://www.w3schools.com/js/js_loop_for.asp",
};
var Value = eval(JSONObject);
document.getElementById("footerboutiques").innerHTML = Value.footerboutiques;
document.getElementById("boutiquelink").href = Value.boutiquelink;
document.getElementById("footerrestaurants").innerHTML = Value.footerrestaurants;
document.getElementById("Restaurantslink").href = Value.Restaurantslink;
document.getElementById("footeracces").innerHTML = Value.footeracces;
document.getElementById("acceslink").href = Value.acceslink;
document.getElementById("footeraerogare").innerHTML = Value.footeraerogare;
document.getElementById("aerogarelink").href = Value.aerogarelink;
}
function ParseJSON2() {
var JSONObject = {
"footerboutiques": "Sourav2 english",
"boutiquelink": "https://developer.mozilla.org/fr/docs/Web/API/Document/getElementById",
"footerrestaurants": "Kayal2",
"Restaurantslink": "https://developer.mozilla.org/fr/docs/Web/API/Document/getElementById",
"footeracces": 242,
"acceslink": "https://developer.mozilla.org/fr/docs/Web/API/Document/getElementById",
"footeraerogare": "1234562" ,
"aerogarelink": "https://developer.mozilla.org/fr/docs/Web/API/Document/getElementById",
};
var Value = eval(JSONObject);
document.getElementById("footerboutiques").innerHTML = Value.footerboutiques;
document.getElementById("boutiquelink").href = Value.boutiquelink;
document.getElementById("footerrestaurants").innerHTML = Value.footerrestaurants;
document.getElementById("Restaurantslink").href = Value.Restaurantslink;
document.getElementById("footeracces").innerHTML = Value.footeracces;
document.getElementById("acceslink").href = Value.acceslink;
document.getElementById("footeraerogare").innerHTML = Value.footeraerogare ;
document.getElementById("aerogarelink").href = Value.aerogarelink;
}
…value='fr')
var value=eval(JSONObject)
若要在id为#lang_link[fr]时返回到网页HTMLF以打开网页,请直接运行函数ParseJSON1,使用$(函数(){if($(“#lang_link\\\[fr\\\])ParseJSON1();else ParseJSON2();