输入为激活/对焦时触发输入开关 [英] Trigger input onchange while input is active/focus

查看:85
本文介绍了输入为激活/对焦时触发输入开关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取表单的提交按钮,以便在设置所有必填字段时更改颜色。

I am trying to get the submit button of a form to change colour when all required field are set....

我可以这样做(sorta)通过这样做:

I can do this (sorta), by doing this:

    if(window.addEventListener) {
            document.getElementById('login_form_form').addEventListener('change', loginSubmitOrange, false);
        } else if (window.attachEvent){
            document.getElementById('login_form_form').attachEvent("onchange", loginSubmitOrange);
        }

该函数检查所需字段是否设置,如果它们是,更改提交按钮的颜色....

the function checks to see that the required fields are set and, if they are, changes the colour of the submit button....

只有在字段从....点击之后才执行。

It only does it after the field is click away from....

我该怎么做,以便在用户打字时触发该功能?不是在用户点击了最后一个必填字段之后?

how do I do it so that the function is triggered while the user is typing? Not after the user has clicked away from the last required field?

我被告知在其他地方,这是不可能的,但我确信我已经看过了。

I have been told, in other places, that it's impossible but I am sure I've seen it before.

另外,没有jquery请....我知道我是一个时髦,但我想从头开始知道一切...

Also, no jquery please....I know I'm being a hipster but I would like to know everything from scratch...

谢谢!

推荐答案

使用键事件而不是 onchange

var elem = document.getElementById('login_form_form');

if(window.addEventListener) {
    elem.addEventListener('keyup', loginSubmitOrange, false);
} else if (window.attachEvent){
    elem.attachEvent("onkeyup", loginSubmitOrange);
}

这篇关于输入为激活/对焦时触发输入开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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