问题描述
在堆栈上的第一个问题,所以欢呼!我试图开发一种新的方法(显然,因为我没有看到这个在线解决方案,也许因为它是不可能的),改变使用JS和lang属性写HTML元素的语言。 p>
基本上,我创建了多个标签,每个标签都带有lang属性,这样给予某个lang显示值-none-,隐藏它, -inherit-来展示它。
这样,使用这一行:
a:lang(en),p:lang(en){显示:无}
a:lang(it),p:lang(it){display:inherit}
我一次可以看到一种语言。现在,我创建了一个
<< ; a href =lang =enid =en>字< / a>
用于标记英文文本,以及与其他语言相同的lang属性。
我尝试过使用:
$ p $ $(#en)。click(function(){
$('a:lang(en)')。css('display','inherit');
$('a:lang(it)')。css('display','none' );
};
这似乎不起作用。
有什么想法?
感谢你们,
Shay
body.en:lang(it)标签将被隐藏。 ){
display:none;
}
body.it:lang(en){
display:none;
}
当您需要更改语言时,只需更改<$ c的 className $ c $< body> 。
$(#en)。click (){
document.body.className ='en';
};
演示:
使用:不是选择器它使用更多的语言。
body:not(.it):lang(it),
body:not(.fr):lang(fr){
display:none;
}
First question on stack, so hurray to me!I'm trying to develop a new way (apparently, since I've seen no solution to this online, perhaps cos it's not possible) to change the language of HTML written elements using JS and the lang property.
Basically, I have created multiple tags with the lang property in each of them, so that giving the certain lang a display value of -none-, hides it, and a value of -inherit- to show it.In that way, using the line:
a:lang(en),p:lang(en) { display : none } a:lang(it),p:lang(it) { display : inherit }
I can see one language at a time. And that works!
Now, I have created an
<a href="" lang="en" id="en"> word </a>
tag around the english text, and the same with any other language with their own lang property.I have tried to use:
$("#en").click(function(){ $('a:lang(en)').css('display', 'inherit'); $('a:lang(it)').css('display', 'none'); };
Which doesn't seem to work.
Any ideas?
Thanks a bunch,Shay
When load your page come with a <body class="it">, and all the :lang(en) tags will be hidden.
body.en :lang(it) { display: none; } body.it :lang(en) { display: none; }
And when you need to change the language, simply change the className of <body>.
$("#en").click(function(){ document.body.className = 'en'; };
Which is more elegant, and way faster.
demo: http://jsfiddle.net/Gw4eQ/
Use :not selector to make it work with more languages. demo
body:not(.en) :lang(en), body:not(.it) :lang(it), body:not(.fr) :lang(fr) { display: none; }
这篇关于html - 使用element.lang更改语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!