-1

我有一个函数,它通过其参数中的一个对象,然后对该对象执行某些操作。

function theFunction (theButton) {
    theButton.addClass('inactive');
}

$('.button').click(function () {
    theFunction($(this));
    return false;
});

问题是它没有将该类应用于按钮。我在这里想念什么?

这是一个带有代码的JS Fiddle

4

3 回答 3

2

您的代码运行良好。你只是忘了包括jquery小提琴。这是更正后的:http: //jsfiddle.net/hNYmd/3/

于 2013-04-12T11:35:06.153 回答
1

你没有加载任何 jQuery

我更新了你的小提琴

http://jsfiddle.net/hNYmd/4/

也更新你的代码

$(document).ready(function(){
        $('.button').click(function () {
            theFunction($(this));
            return false;
        });
});
于 2013-04-12T11:34:25.650 回答
1

你应该像这样把你的代码放在 dom 上,FIDDLE

    function theFunction (theButton) {
        theButton.addClass('inactive');
    }
    $(function(){
        $('.button').click(function () {
            theFunction($(this));
            return false;
        })
    })
于 2013-04-12T11:44:11.063 回答