English 中文(简体)
在JQuery用 h和点击来改变DIV颜色
原标题:Changing DIV colors using hover and click in JQuery

请允许我提供帮助。 我有:

我希望案文在被点击时改写为轻绿。

$(".music").hover(
    function() {
        $(this).css( color , lightgreen );
    }, 
    function() {
        $(this).css( color ,  white );
    }
);

$(".music").click(function () { 
    $( #result ).load( album_list_index.php );
    $(this).css({  color :  red ,  font-size :  100%  });
});

事先感谢你

AC

NOTE: ok im sorry i没有表明自己。

I need the div to be white when not mousedover I need it to be gree when mouseover And i need it to be red when clicked, and remain red until another button is clicked.

感谢大家的投入,大体是加级,删除班级案件,这是一个很好的教训,我一旦掌握了这一技术,就将使用更多的东西。

最佳回答

The problem is when i click the item it turns red but then it reverts to white and i hover off it

如果你希望有<条码>click<>/条码>,你就会更好地利用班级。 引证:

a { color: white; }
.active { color: red; }
.hover { color: lightgreen; }
$(".music").hover(
    function() {
        $(this).addClass("hover");
    }, 
    function() {
        $(this).removeClass("hover");
    }
);

$(".music").click(function () { 
    $( #result ).load( album_list_index.php );
    $(".music").removeClass("active");
    $(this).removeClass("hover").addClass("active");
});

rel=“nofollow”>Example fiddle

问题回答

您可使用CSS的假件::hover:active

Or, when using jQuery, use the .hover() and .click() methods.

Just wrap you code in a $(document).ready(function() { // code here }); and it will work.

建议使用特别安全局......但你仍然可以做一些工作。

  $(document).ready(function(){
        $(".music").mouseover(function() {
           if(!$(this).hasClass( dontchange )){
              $(this).css( color , lightgreen );
           }
        });
        $(".music").mouseout(function() {
               if(!$(this).hasClass( dontchange )){
                $(this).css( color ,  white );
             }
        }

        $(".music").click(function () { 
         $(this).addClass( dontchange );
        $( #result ).load( album_list_index.php );
        $(this).css({  color :  red ,  font-size :  100%  });
        });
        });




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签