悬停按钮使用jQuery的? [英] Hovering on buttons using jquery?

查看:119
本文介绍了悬停按钮使用jQuery的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Doing a hovering event on button as below.

JQuery代码是:

<div id="common_id"> <div class="button" id="make_larger"> <button type="button">Large</button> </div> <div class="button" id="make_small"> <button type="button">Smaller</button> </div> <div class="button" id="make_normal"> <button type="button">Normal</button> </div> </div>

JQuery code is:

Css是:

$('#common_id .button').hover(function () { $(this).addClass('hover1'); }, function () { $(this).removeClass('hover1'); });

Css is:

将鼠标放在按钮上时,完整的行到页的末尾)变黑,即使按钮没有变黑,但它的背景在该行看起来是黑色的。
我想让按钮在我悬停时变成黑色。
为什么它不工作?

.hover1 { background-color:Black; position:relative; }

预先感谢。

推荐答案

div取100%的宽度。所以不要选择div来选择按钮。所以你的选择器应该看起来像这样

the div is taking the 100% width. so instead of selecting the div select the button. So your selector should look like this

$('#common_id .button button').hover(function () {
            $(this).addClass('hover1');
        }, function () {
            $(this).removeClass('hover1');

        });​

试试这个小提琴

这篇关于悬停按钮使用jQuery的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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