开发者

Toggle background color with click in and out

开发者 https://www.devze.com 2023-01-14 14:33 出处:网络
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

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.ge开发者_运维技巧tElementById("test");

         input.onclick = function ()
         {
         document.getElementById("quote_input").style.backgroundColor = "#AAB3AA";
         document.getElementById("test").style.backgroundColor = "#AAB3AA";

 };});
 </script>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消