日期:2014-05-16  浏览次数:20350 次

jq多个按钮绑定同一个事件,单击按钮后如何获得当前点击的按钮
如题,我制作软键盘,根据class批量绑定按钮事件
$(".keyboardm").bind("click", this, this._ButtonClickHandle);
我如何知道当前点击的按钮是哪个
------解决方案--------------------
$(".keyboardm").bind("click", this, $.proxy(this._ButtonClickHandle,this));




------解决方案--------------------
你的事件处理函数中this就是当前对象了
------解决方案--------------------
proxy: function( fn, context ) {
var args, proxy, tmp;

if ( typeof context === "string" ) {
tmp = fn[ context ];
context = fn;
fn = tmp;
}

// Quick check to determine if target is callable, in the spec
// this throws a TypeError, but we will just return undefined.
if ( !jQuery.isFunction( fn ) ) {
return undefined;
}

// Simulated bind
args = core_slice.call( arguments, 2 );
proxy = function() {
return fn.apply( context 
------解决方案--------------------
 this, args.concat( core_slice.call( arguments ) ) );
};

// Set the guid of unique handler to the same of original handler, so it can be removed
proxy.guid = fn.guid = fn.guid 
------解决方案--------------------
 jQuery.guid++;

return proxy;
},


简单==
proxy: function( fn, context ) {args = core_slice.call( arguments, 2 );
proxy = function() {
return fn.apply( context 
------解决方案--------------------
 this, args.concat( core_slice.call( arguments ) ) );
}; return proxy;
},