How would you do something like this:
你会怎么做这样的事情:
somemethod($("#buttonelement"));
function(ele) {
ele.click(function(event) { alert("hi"); });
}
in other words how do you pass in an element as a jquery object and register the click event.
换句话说,如何将元素作为jquery对象传递并注册click事件。
1 个解决方案
#1
Just like that...?
就像那样......?
function someMethod(ele) {
ele.click(function(event) {
alert("hi");
});
}
someMethod($("#buttonelement"));
The jQuery object is just like any other object in Javascript and can be passed to functions as normal.
jQuery对象就像Javascript中的任何其他对象一样,可以像往常一样传递给函数。
#1
Just like that...?
就像那样......?
function someMethod(ele) {
ele.click(function(event) {
alert("hi");
});
}
someMethod($("#buttonelement"));
The jQuery object is just like any other object in Javascript and can be passed to functions as normal.
jQuery对象就像Javascript中的任何其他对象一样,可以像往常一样传递给函数。