任何事件触发自动完成? [英] Any event triggered on autocomplete?

查看:158
本文介绍了任何事件触发自动完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个pretty简单的形式。当用户在输入栏,我想更新他们所输入的内容在其他地方在页面上。这一切工作正常。我已经绑定的更新到 KEYUP 变更点击事件。

唯一的问题是,如果你选择浏览器的自动完成框输入时,它不会更新。有当您从自动完成选择触发任何情况下(这显然既不更改也不点击)。需要注意的是,如果你从自动完成框中选择和的模糊的输入字段,更新就会​​被触发。我想它要尽快触发的自动完成。

请参阅: http://jsfiddle.net/pYKKp/ (希望你已经填写了大量的形式在过去与输入名为邮件)。

HTML

 <输入名字=电子邮件/>
< D​​IV ID =无所谓>&放大器; LT;凡是>< / DIV>

CSS:

  DIV {
    浮动:权利;
}

脚本:

  $(输入)。在('KEYUP改变点击',功能(){
   变种V = $(本).VAL();
    如果(ⅴ){
     $(#无所谓)文本(V)。
    }
    其他{
        $(#无所谓)文本。('<凡是>');
    }
});


解决方案

我推荐使用 monitorEvents 。这是一个功能由两个JavaScript控制台<一个提供href=\"http://developer.apple.com/library/safari/#documentation/appleapplications/Conceptual/Safari_Developer_Guide/DebuggingYourWebsite/DebuggingYourWebsite.html\">web督察和<一个href=\"http://getfirebug.com/wiki/index.php/Command_Line_API#monitorEvents.28object.5B.2C_types.5D.29\">firebug打印出由一个元件产生的所有事件。下面是你如何使用它的例子:

  monitorEvents($(输入)[0]);

在你的情况下,Firefox和Opera都产生一个 输入当用户选择从自动完成一个项目的下拉事件。在IE7-8和Chrome一个 更改 事件就产生了。不幸的是浏览器不产生任何类似事件,所以你被卡住听着模糊事件和手动检查是否发生了改变文本

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 .

See: http://jsfiddle.net/pYKKp/ (hopefully you have filled out a lot of forms in the past with an input named "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>'); 
    } 
}); 

解决方案

I recommending using monitorEvents. It's a function provide by the javascript console in both web inspector and firebug that prints out all events that are generated by an element. Here's an example of how you'd use it:

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 and Chrome a change event is produced after the user changes focus. Unfortunately chrome does not generates any similar events, so you are stuck with listening to blur events and manually checking if a text change has occurred.

这篇关于任何事件触发自动完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆