具有活动onclick事件的Onclick重新加载页面

时间:2018-09-23 12:47:08

标签: javascript html css

我制作了多语言索引页面,当我单击我的语言链接(AZ,EN,RU)页面时,我希望重新加载具有每个链接的onclick函数(translateTo(“ AZ”); under1();返回false;)。我也想在代码中使用纯JavaScript。
这是我的代码;

var voc = [
            {
              "AZ":"Log in2",
              "EN":"Log in",
              "RU":"Log in3"
            }
          ];


function translate(ele,lng){
 for(var i=0;i<voc.length;i++){
  for(var k in voc[i]){
   if(voc[i][k] == ele.innerText.trim()){
    ele.innerText = voc[i][lng];
    break;
   }
  }
 }
}
function translateTo(lng){
var trc = document.getElementsByClassName("trans");
for(var i=0;i<trc.length;i++){
translate(trc[i],lng);
}
}
//add this function to any event button.click,select.change or on load
//translateTo("AR");

function under1(){
  document.getElementsByClassName("lang")[0].style = "text-decoration:underline;";
  document.getElementsByClassName("lang")[1].style = "text-decoration:none";
  document.getElementsByClassName("lang")[2].style = "text-decoration:none";
}

function under2(){
  document.getElementsByClassName("lang")[0].style = "text-decoration:none;";
  document.getElementsByClassName("lang")[1].style = "text-decoration:underline";
  document.getElementsByClassName("lang")[2].style = "text-decoration:none";
}

function under3(){
  document.getElementsByClassName("lang")[0].style = "text-decoration:none;";
  document.getElementsByClassName("lang")[1].style = "text-decoration:none";
  document.getElementsByClassName("lang")[2].style = "text-decoration:underline";
}
.langselect a{
text-decoration:none;
}

.langselect a:nth-child(2){
text-decoration:underline;
}
<p>
<span class='trans'>Log in</span> 
</p>

<p class="langselect">
<a href="" class="lang" onclick='translateTo("AZ"); under1(); return false;'>AZ</a>
<a href="" class="lang" onclick='translateTo("EN"); under2(); return false;'>EN</a>
<a href="" class="lang" onclick='translateTo("RU"); under3(); return false;'>RU</a>
</p>

0 个答案:

没有答案