通过点击进入和退出切换背景颜色
我有一个效果很好的脚本,但当您离开或单击 .test 之外时,我需要背景颜色返回到其原始状态
有没有办法让它在单击 .test 之外后切换回来?
这是我的代码:
<script type="text/javascript">
$(document).ready(function() {
var input = document.getElementById("test");
input.onclick = function ()
{
document.getElementById("quote_input").style.backgroundColor = "#AAB3AA";
document.getElementById("test").style.backgroundColor = "#AAB3AA";
};});
</script>
I have a script that works great, but I need the background color to return to its original state when you leave or click outside the .test
Is there a way to make it toggle back after clicking out of the .test?
Here is my code:
<script type="text/javascript">
$(document).ready(function() {
var input = document.getElementById("test");
input.onclick = function ()
{
document.getElementById("quote_input").style.backgroundColor = "#AAB3AA";
document.getElementById("test").style.backgroundColor = "#AAB3AA";
};});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将旧的背景颜色存储在另一个变量中,或者作为元素的属性,然后在
onmouseout
事件中,您将读取该属性并反转背景。You could store the old background color in another variable, or as an attribute on the element, and then on the
onmouseout
event, you would read that attribute and reverse the backgrounds.