根据语言选择更改网址链接

时间:2019-06-21 03:12:18

标签: javascript html arrays ajax object

我已经实现了一个网站,其中navbar标头具有下拉菜单的多语言选项,将所有锚标签链接更改为该lanaguage,

我有一个单独的头文件,并且包含在每个页面中, 如何使用ajax调用或任何替代方法实现它。

当我选择语言下拉菜单时,如何在选择法语时将href链接/ en更改为/ fr


index.ejs
<body>
   <%- include header.ejs %>
   <h1>Welcome to my Site</h1>
</body>
about.ejs
<body>
   <%- include header.ejs %>
   <h1>About Us</h1>
</body>

header.ejs

<nav class="navbar navbar-expand-md navbar-light bg-light fixed-top pb-0">
    <a class="navbar-brand" href="/en"><img src="/images/logo.png" alt="" style="max-width: 100px"></a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar"><span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse justify-content-between" id="collapsibleNavbar">
        <ul class="navbar-nav mr-auto">
           <li class="nav-item">
                <a class="nav-link" href="/en/aboutus"
                    style="margin-right: 1.5rem!important;">About</a>
            </li>
           <li class="nav-item">
                <a class="nav-link" href="/en/aboutus"
                    style="margin-right: 1.5rem!important;">Contact</a>
            </li>
        <ul class="navbar-nav">
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="dropdownmenu" data-toggle="dropdown" aria-haspopup="true"
                    aria-expanded="false">Dropdown</a>
                <div class="dropdown-menu" aria-labelledby="dropdownmenu">
                    <a class="dropdown-item" href="/en">english</a>
                    <a class="dropdown-item" href="/fr">french</a>
                </div>
            </li>
        </ul>
    </div>
</nav>

0 个答案:

没有答案