.focus()没有用.parent()添加类

时间:2012-12-17 23:17:29

标签: jquery button focus parent addclass

有一个问题我似乎无法动摇。我有几个表行,我正在使用jQuery突出显示它们被点击。我的一些行有一个输入/按钮/复选框/ textarea,因此它们不是由跨度描绘的,而我正在使用另一个只有两个父项的函数。那些工作正常。所谓的“跨度输入”也是如此。另一方面,“span按钮”不添加活动类。奇怪的是,如果我在桌面浏览器中查看它并单击它,激活另一个应用程序的窗口或在浏览器中添加一个新选项卡,然后单击返回它,它会突出显示应该是。

不知道发生了什么。请帮忙!非常感谢!

HTML:

<tr>
    <td class="input">
        <span>
            <label for="buttonA">ButtonA Label</label>
            <button name="buttonA" type="button"/>ButtonA</button>
        </span>
        <span>
            <label for="buttonB">ButtonB Label</label>
            <button name="buttonB" type="button"/>ButtonB</button>
        </span>
    </td>
    <td class="unit">
        Unit
    </td>
    <td class="info">
        Description or additional info</br>
        With multiple lines
    </td>
    <td class="action">
        <div id="delete" class="btn"><img src="delete_icon.png"></div>
        <div id="drag" class="btn"><img src="drag_icon.png"></div>
    </td>
</tr>

CSS:

.active {
    background: rgb(227,238,255) !important;
}

jQuery的:

$("span input,span button").focus(function() {
    $(this).parent().parent().parent().addClass('active');
});

0 个答案:

没有答案