I have a pretty simple form. When the user types in an input field, I want to update what they've typed somewhere else on the page. This all works fine. I've bound the update to the keyup, change and click events.

The only problem is if you select an input from the browser's autocomplete box, it does not update. Is there any event that triggers when you select from autocomplete (it's apparently neither change nor click). Note that if you select from the autocomplete box and the blur the input field, the update will be triggered. I would like for it to be triggered as soon as the autocomplete .

请看:http://jsfiddle.net/pYKKp/(希望您过go 已经用名为"Email"的输入填写了很多表单).

HTML:

<input name="email" /> 
<div id="whatever">&lt;whatever></div> 

CSS:

div { 
    float: right; 
} 

Script:

$("input").on('keyup change click', function () { 
   var v = $(this).val(); 
    if (v) { 
     $("#whatever").text(v);   
    }  
    else { 
        $("#whatever").text('<whatever>'); 
    } 
}); 

推荐答案

我推荐使用monitorEvents.它是web inspectorfirebug中的javascript控制台提供的函数,用于打印元素生成的所有事件.下面是一个如何使用它的示例:

monitorEvents($("input")[0]);

In your case, both Firefox and Opera generate an input event when the user selects an item from the autocomplete drop down. In IE7-8 a change event is produced after the user changes focus. The latest Chrome does generate a similar event.

A detailed browser compatibility chart can be found here:
https://developer.mozilla.org/en-US/docs/Web/Events/input

Jquery相关问答推荐

当父迪瓦是重复元素时,如何将一些子元素包裹在父迪瓦中

将元素附加到每个函数 jQuery

jQueryUI 模态对话框不显示关闭按钮 (x)

如何用另一个响应替换窗口的 URL 哈希?

为什么我们在 jQuery 中使用({ })?

清除并刷新 jQuery Chosen 下拉列表

Rails,单击link_to helper后未加载javascript

有没有办法放大 D3 力布局图?

在没有 jQuery 的情况下在 node.js 上合并或合并 JSON

如何使用jQuery动态设置宽度和高度

jQuery用另一个类替换一个类

未捕获的 TypeError:data.push 不是函数

jQuery - 多个 :not Select 器

jQuery:如何找到第一个可见的输入/ Select /文本区域,不包括按钮?

JQuery:如果 div 可见

如何使用 javascript 擦除所有内联样式并仅保留 css 样式表中指定的样式?

检测 jQuery UI 对话框是否打开

如何复制 pinterest.com 的绝对 div 堆叠布局

如何禁用由子元素触发的 mouseout 事件?

Drop 事件未在 chrome 中触发