简体   繁体   English

在onClick方法中调用JavaScript函数

[英]Calling JavaScript functions in the onClick method

I have this function 我有这个功能

    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";
    }
}

and call it inline like this 并这样称呼它

<img src="../../en/EN.png" class="flag" onclick="setLang('en')">

So this is where I want to access it from, from a onclick function. 因此,这是我想通过onclick函数从中访问它的地方。

I'm quite new to JS, So that's why I'm asking how can I do that. 我是JS的新手,所以这就是为什么我问我该怎么做。

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM