我正在寻找一种为jQuery实现自定义"enterKey"事件的方法:
$('selector').enterKey(function(){
alert( $(this).val() ) // doesn't work
});
Run Code Online (Sandbox Code Playgroud)
我做了类似于/sf/answers/398240181/的事情 ,它有一个例外:我无法从我的匿名函数中访问$(this)
我想要的简化版本:
$.fn.test = function( ev ) {
ev();
}
$('#val').test( function(){
alert( $(this).val() ); // works well with static text,
//but not with "this" pointer
});
Run Code Online (Sandbox Code Playgroud)
任何帮助都会被贬低
jquery ×1