【发布时间】:2012-01-20 03:48:14
【问题描述】:
在 html 页面内的标准文本框中,当用户输入浏览器可识别的部分内容并显示“自动完成下拉菜单”时:
当用鼠标选择/单击它,从而在其文本框中输入值时,会触发什么 javascript 事件?
$('#txt').blur(function () { console.log('text changed'); });
$('#txt').change(function () { console.log('text changed'); });
$('#txt').click(function () { console.log('text changed'); });
$('#txt').focus(function () { console.log('text changed'); });
$('#txt').focusin(function () { console.log('text changed'); });
$('#txt').focusout(function () { console.log('text changed'); });
$('#txt').mousedown(function () { console.log('text changed'); });
$('#txt').mouseenter(function () { console.log('text changed'); });
$('#txt').mouseleave(function () { console.log('text changed'); });
$('#txt').mouseout(function () { console.log('text changed'); });
$('#txt').mouseover(function () { console.log('text changed'); });
$('#txt').select(function () { console.log('text changed'); });
这些都不起作用!
【问题讨论】:
-
"change" 将在您 Tab 或单击该字段时触发(在从自动完成中选择一个选项后)。请注意,即使它们起作用,鼠标事件也不够,因为您可以使用键盘上的浏览器自动完成功能。
-
this is selected,您的意思是建议列表中的自动完成项?你用的是什么插件? -
键盘事件工作正常,这就是为什么它们不是这个问题的一部分。
-
@DidierG。没有插件,浏览器在最新版本的 chrome 和 firefox 上原生实现自动完成。
-
你找到解决办法了吗?
标签: javascript jquery events