我是JavaScript和Bootstrap的初学者,我添加了导航栏,但是我想通过单击导航栏顶部的按钮来更改导航栏标题语言(首页,关于我们,我们的服务,联系我们)。下面是引导代码。
<button type="button" class="btn btn-primary">Spanish</button>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<img src="images/logo.png" width="60" height="55" class="d-inline-block align-top" alt="" loading="lazy">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto text-center">
<li class="nav-item active">
<a class="nav-link" href="index.html">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="aboutus.html">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="ourservices.html">Our Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contactus.html">Contact Us</a>
</li>
</ul>
<a class="btn btn-outline-primary" id="fire" href="http://eatxact.com/#">Login</a>
</div> </nav>
答案 0 :(得分:1)
您可以为某些语言(例如“ en”或“ uk”)创建语言环境,并将其添加到网站的网址,然后单击按钮即可将其重定向到正确的本地化页面。
但是它将重新加载页面。如果您不想这样做,Siddharth S.的答案是最好的选择