Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想将一些函数存储在变量中,如下所示:
var x = function() { //do something here }
例如,您将如何在 onclick 中调用该函数?
尝试这个
$('#element').on('click',function(){ x(); });
或者
$('#element').on('click',x);
演示
$(selector).click(x);
$(selector).click(function() { x(); });