在javascript中更改背景颜色 [英] change background color in javascript

查看:82
本文介绍了在javascript中更改背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有人的甜蜜一天

我的问题是,当鼠标光标进入背景颜色已更改的区域路径时,我需要用Java脚本语言制作地图

我该怎么办或给我一个网站可以帮助我

谢谢&&最好的问候4 All

Sweet day for all

my Question is i need to make map in java script language when the mouse curser enter the region path the background color has changed

how can i do this or give me a site can help me

Thanks && Best Regards 4 All

推荐答案

定义颜色的唯一好的样式是CSS.因此,在JavaScript中执行此操作的唯一好方法是更改​​或添加元素的样式.最方便的方法之一是使用jQuery:
http://en.wikipedia.org/wiki/JQuery [ http://jquery.com/ [ ^ ].

您可以使用jQuery .addClass.removeClass.toggleClass方法:
The only good style of defining colors is CSS. Therefore, the only good way to do this in JavaScript is changing or adding the style of the element. And one of the most convenient way of doing this is using jQuery:
http://en.wikipedia.org/wiki/JQuery[^],
http://jquery.com/[^].

You can use the jQuery .addClass, .removeClass or .toggleClass methods:
myElement =


(" ); // 在HTML中用id ="myElement"标记元素的元素 className = " ; myElement.addClass(className); // 变红 myElement.removeClass(className); // 恢复以前的类,从而恢复CSS属性 // myElement.toggleClass(className); // 切换它
("#myElement"); //find element where the element is marked with id="myElement" in HTML className = "yellowBackground"; myElement.addClass(className); //make red myElement.removeClass(className); //restore previous classes and hence CSS properies //or myElement.toggleClass(className); //toggle it



自然,您将需要CSS中的对应类:



Naturally, you would need the correspondent classes in CSS:

.yellowBackground { background-color: yellow; }



请参阅:
http://api.jquery.com/addClass/ [ http://api.jquery.com/removeClass [ http://api.jquery.com/toggleClass/ [ http://docs.jquery.com/Tutorials [ http://docs.jquery.com/Tutorials:How_jQuery_Works [



Please see:
http://api.jquery.com/addClass/[^],
http://api.jquery.com/removeClass[^],
http://api.jquery.com/toggleClass/[^].

Learning jQuery is easy and a kind of fun. Start here:
http://docs.jquery.com/Tutorials[^],
http://docs.jquery.com/Tutorials:How_jQuery_Works[^].

—SA


这篇关于在javascript中更改背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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