2
我正在寻找一种方式来实现自定义“enterKey”事件的jQuery:
$('selector').enterKey(function(){
alert($(this).val()) // doesn't work
});
我已经做了类似的东西https://stackoverflow.com/a/5689145/1123630 ,并与工作一个例外:我无法将匿名函数内访问$(本)从
的我想要的简化版:
$.fn.test = function(ev) {
ev();
}
$('#val').test(function(){
alert($(this).val()); // works well with static text,
//but not with "this" pointer
});
任何帮助将是aprec iated
谢谢。我很惊讶,我错过了这一点。 – Liviuge 2011-12-30 23:20:16
演示:http://jsfiddle.net/LbzKX/ – 2011-12-30 23:20:38
对于记录良好的答案+1 – Chad 2011-12-30 23:22:46