哪个事件被解雇了? (javascript,input-field-history) [英] Which Event is fired? (javascript, input-field-history)

查看:46
本文介绍了哪个事件被解雇了? (javascript,input-field-history)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个空白的文本字段,但是当你点击它时它会有一些来自先前输入的建议。

I have a text field which is empty, but when you click in it it has some suggestions from previous inputs.

如果我选择一个,会触发哪个JavaScript事件他们用鼠标?

Which JavaScript event is fired if i choose one of them with the mouse?

我正在使用jquery 1.6.2来绑定听众:

i'm using jquery 1.6.2 for binding the listeners:

view.textRegistrations.bind("blur change keyup", function(event) {
    //do Something
});


推荐答案

触发oninput事件。

the oninput event triggered.

尝试:

    <!doctype html>
    <html>
        <head>
            <meta charset="utf-8">
            <title>title</title>
        </head>
        <body>
            <form method="get" id="" action="">
                <input type="text" name="name" oninput="alert('oninput')"/>
                <input type="submit" value="done"/>
            </form>
        </body>
    </html>

oninput,onpropertychange,onchange之间的差异:

the diffrence between oninput,onpropertychange,onchange:

onchange 仅在

时触发a)用户界面更改的属性

a)the property changed by user interface

b)并且元素失去焦点

b)and the element lost focus

onpropertychange 在属性更改时触发。但它只是IE浏览器

onpropertychange fires when property change. but it is IE only

oninput

oninput是onpropertychange的W3C版本。 IE9开始支持此事件。

oninput is the W3C version of onpropertychange . IE9 begin surport this event .

oninput仅在元素值更改时触发。

oninput fired only when the element value changes.

所以如果你想在所有浏览器中使用compacity

so if you want compacity in all browsers

IE< 9使用onpropertychange

IE<9 use onpropertychange

IE> 9和其他浏览器使用oninput

IE>9 and other broweser use oninput

如果你使用jQuery,你可以绑定两个共享同一个hander的事件

if you use jQuery , you can bind two event that share the same hander

$(function($) {
  //the same handler
  function oninput(e){
    //do sth
  }

  $("#ipt").on("input", function(e){
    console.log("trigger by oninput");
    oninput(e);
  })

  $("#ipt").on("propertychange", function(e) {
    console.log("trigger by propertychange");
    oninput(e);
  })
}) 

演示 http://output.jsbin.com/salekaconi

这篇关于哪个事件被解雇了? (javascript,input-field-history)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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