我有这个功能
function setLang(ln){
if(ln == "en"){
window.location = "../../en/page/login.html";
}else if(ln == "de"){
window.location = "../../de/page/login.html";
}else if(ln == "fr"){
window.location = "../../fr/page/login.html";
}
}
并像这样将其称为内联
<img src="../../en/EN.png" class="flag" onclick="setLang('en')">
所以我想从onclick
函数中访问它。
我对JS很陌生,这就是为什么我要问我该怎么做。
答案 0 :(得分:0)
<img src="../../en/EN.png" class="flag" onclick="setLang('en')"/>
<script>
function setLang(ln){
if(ln == "en"){
window.location = "../../en/page/login.html";
}else if(ln == "de"){
window.location = "../../de/page/login.html";
}else if(ln == "fr"){
window.location = "../../fr/page/login.html";
}
}
</script>