根据点击更改网址 [英] Change URL depending on click

查看:71
本文介绍了根据点击更改网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将语言切换器添加到特定的html页面。我不需要任何语言文本,只有通过点击才能更改另一个网站的链接。
在这里创建三个html页面并没有什么意义,只是为了处理一些链接变化,但我的jQuery技能并不是那么好。

目的地结构如下所示:

 < ul> 
< li>< a class =clickButtonhref =folder1 / firstLink / Languages / English / folder / index.html>索引链接< / a>< / li>
< li>< a class =clickButtonhref =../ folder2 / secondLink / Languages / English / folder / index.html>不同的连结< / a>< / li> ;
< li>< a class =clickButtonhref =../../ folder3 / Languages / English / folder / index.html>另一个不同的连结< / a>< / li> ;

< ul>

< ul>
< li>< a class =clickButtonhref =folder1 / firstLink / Languages / Spanish / folder / index.html>索引链接< / a>< / li>
...
< ul>

正如您所看到的,我只需要用西班牙语替换语言名称(英语)为了使链接工作。
所以我认为用户点击了相应的标志和url字符串会相应地改变。



我会很高兴看到一些例子如何切换语言名称

解决方案

使自己变得容易:向链接添加自定义数据属性;

 < a data-lang =Englishhref => 

用jQuery通过 $ link.data('lang')来访问它; 并将其添加到href。


I want to add a language switcher to a specific html page. I don't need any language text only the link to another site will need to be changed depending on the click. It wouldn't make much sense here to create three html pages just to deal with some link change but my jquery skills are not that great.

The destination structure looks like this:

<ul>
<li><a  class="clickButton" href="folder1/firstLink/Languages/English/folder/index.html">Index Link</a></li>
<li><a  class="clickButton" href="../folder2/secondLink/Languages/English/folder/index.html">A different Link </a></li>
<li><a  class="clickButton" href="../../folder3/Languages/English/folder/index.html">Another different link</a></li>

<ul>

<ul>
<li><a  class="clickButton" href="folder1/firstLink/Languages/Spanish/folder/index.html">Index Link</a></li>
...
<ul>

As you can see I would only need to replace the language name ("English") with Spanish in order to make the link work. So I was thinking that the user clicks on the according flag and the url string changes accordingly.

I would be happy about some example how to switch the language name

解决方案

make it easy for yourself: add custom data attribute to links;

<a data-lang="English" href="">

Than access it with jQuery by $link.data('lang'); and add it to the href.

这篇关于根据点击更改网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆