2013-04-12 31 views
-1

我有一个函数在其参数中传递一个对象,然后对该对象执行某些操作。通过函数传递后无法将对象添加到对象 - jQuery

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

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

问题是它不会将该类应用于按钮。我在这里错过了什么?

这里有一个JS Fiddle与代码中。

+0

您还没有加载jQuery的http://jsfiddle.net/hNYmd/6/ – undefined

+0

嗯转jQuery上为你的小提琴可能? http://jsfiddle.net/calder12/hNYmd/7/ –

+0

在你的小提琴中加载jquery –

回答

1

你没有加载任何的jQuery

我已经更新了你的提琴

查阅

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

更新你的代码也

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

你应该把你的代码在DOM准备这样,FIDDLE

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