附加事件清除IE10文本框中的图标 [英] Attach event to clear icon in IE10 textbox

查看:136
本文介绍了附加事件清除IE10文本框中的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IE10中,一个小的X图标出现在文本框中以清除输入文本。如何将一个事件附加到该动作(=单击该X并清除输入)?

解决方案

似乎没有一个确切的事件( onchange 不适合)。但是,您可以使用 oninput 并检查输入的值是否为空:

  document.getElementById('input_ID')。addEventListener('input',function(){
if(this.value ===' '){
alert('No value');
}
},false);

如果用户清除输入带有 BACKSPACE DELETE ,或将内容剪切到剪贴板。 oninput 至少可以在Chrome,FF,IE10和Opera中使用。


In IE10 a small X icon appears in the textbox to clear the input text. How can an event be attached to that action (=clicking on that X and clearing the input)?

解决方案

It seems there's not an exact event for this (onchange is not suitable). However, you can use oninput and check, if the value of the input is empty:

document.getElementById('input_ID').addEventListener('input', function () {
    if (this.value === '') {
        alert('No value');
    }
}, false);

This event is triggered also, if user clears the input with BACKSPACE or DELETE, or cuts the content to the clipboard. oninput works at least in Chrome, FF, IE10 and Opera.

这篇关于附加事件清除IE10文本框中的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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