javascript更改背景颜色点击 [英] javascript change background color on click

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

问题描述

我是一个新的编程,我试图学习新的方法和方法...

I am kind of new to programming and I am trying to learn new methods and ways...

你能告诉我一个Javascript,页面颜色的背景颜色到另一个。例如,我有一个蓝色的背景颜色,我想把它改为绿色。当用户单击背景并触发事件时,应更改颜色。

Can you show me a Javascript that makes it possible to change the color of page background color to another one . For example, i have a blue background color and i want to change it to green. The color should be changed when the user clicks on the background and triggers the event.

此外,Div也一样,点击时改变颜色,但10秒后,它会返回初始颜色。它是clearInterval的东西,但我不是一个专家.yet。

Also..the same thing for a Div, change color on click, but after 10 seconds, it would return to initial color. It's something with clearInterval, but i am not an expert..yet.

谢谢...

推荐答案

如果您想要在HTML页面中通过点击按钮更改背景颜色,则将使用JavaScript函数并更改HTML页面中的样式。

If you want change background color with click in button in HTML page you will be use JavaScript function and change a style in HTML page.

function chBackcolor(color) {
   document.body.style.background = color;
}

这是JavaScript中用于更改颜色的函数,例如:

It is a function in JavaScript for change color, and you will be call this function in your event, for example :

<input type="button" onclick="chBackcolor('red');">

我的意见是你使用 JQuery

如果你想在第二次或时间执行,你将使用setTimeout函数:

If you want perform in second or time you will be use setTimeout function:

window.setTimeout("chBackColor()",10000);

我经常在HTML页面中使用此方法隐藏警报。

I use this method for hidden alert in HTML page often.

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

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