【发布时间】:2010-09-16 00:06:54
【问题描述】:
我试图通过.live() jQuery 方法将一个简单的焦点/模糊事件侦听器附加到我的输入,但我注意到focus 事件没有触发,而blur 事件是。
奇怪……希望你知道为什么会这样。
代码如下:
function rowHighlight() {
var form = $('form.register'),
ele = {};
form.find('label').each(function(i) {
var link = this.htmlFor;
form.find('label[for='+link+'],input[name='+link+'],textarea[name='+link+']').wrapAll('<span class="row"/>');
});
ele.row = $('form > .row');
ele.inputs = ele.row.find('input');
$.each(ele.inputs, function(i) {
$(this).focus(function() {
console.log('hello'); // this will fire.
});
$(this).live('focus blur', function(e) {
console.log('current event type: '+e.type); // the focus on this will not fire!?
( e.type=='focus' ? console.log('focussed') : console.log('blurred') )
});
});
}
rowHighlight();
$(this).focus… 只是把它作为调试的东西,删除它不会使live 侦听器上的focus 工作......
任何帮助将不胜感激。
感谢您的光临。
詹尼斯
【问题讨论】:
标签: javascript jquery events forms input