![](/img/trans.png)
[英]Is it possible in CSS to change the style of an element by clicking on an other?
[英]is it possible that by clicking, the class of the element change?
我想为我的网站设置一个开关,当您单击它时页面的语言会更改。 昨天我在一个网站上看到了一个真实的例子。
这是链接: http : //iranfilm76.com/
标头左侧的对象正是我要实现的对象,但是我不想更改背景,而是要更改语言。
我已经具有更改语言的功能,我的问题是对象,我下载了图像和CSS的文件。
我仔细查看了带Firebug的代码,当您单击标记时,标记的类将更改为class="changestyle"
。
我怎样才能做到这一点? 感谢您的任何建议。
YOUR_ELEMENT.addEventListener("click", function(){
this.classList.toggle("changestyle");
});
演示: http : //jsfiddle.net/DerekL/KpwkG/ | http://jsfiddle.net/WsGGa
对于非纯JavaScript方法,您可以尝试使用jquery选择您的toggle元素,如下所示:
$('element').click(function(){
$(this).toggleClass('language');
});
然后,您可以在CSS中应用所需的任何规则
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.