是否有可能改变背景颜色,并回到原来的纯JavaScript的时候我每次点击一个按钮? [英] Is it possible to change the background color and back to the original in plain javascript every time i click a button?
本文介绍了是否有可能改变背景颜色,并回到原来的纯JavaScript的时候我每次点击一个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎无法看到谷歌的任何结果,除非我使用jQuery,我不敢肯定,如果jQuery和JavaScript的纯一起工作。
I can't seem to see any results on google unless I use jQuery and I'm not so sure if jQuery and javascript plain work together.
推荐答案
jQuery将无法使用JavaScript冲突,它只是一个JS库:)所以,你可以使用 selector.css()
的jQuery,或在标准JS我认为这是(元素).style.background =颜色
。
jQuery will not conflict with javascript, it is just a js library :) So you can use the selector.css()
of jquery or, in standard js i think it is (element).style.background = color
.
我建议使用jQuery。下面是一个简单的jQuery办法做到这一点:
I recommend using jQuery. Here is a SIMPLE jQuery way to do it:
$("#button").click(function(){
$("#tochange").css("background-color", "colorhex");
});
如果您希望交换的颜色,你可以,例如,添加一个变量。
If you want to swap colors you could, for example, add a variable.
var x;
$("#button").click(function(){
if(x==0){
$("#tochange").css("background-color", "colorhex");
x= 1;
}
else{other way round}
});
这篇关于是否有可能改变背景颜色,并回到原来的纯JavaScript的时候我每次点击一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文