通过点击进入和退出切换背景颜色

发布于 2024-09-16 04:32:26 字数 497 浏览 1 评论 0原文

我有一个效果很好的脚本,但当您离开或单击 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哽咽笑 2024-09-23 04:32:26

您可以将旧的背景颜色存储在另一个变量中,或者作为元素的属性,然后在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文