Attach event to clear icon in IE10 textbox(附加事件以清除 IE10 文本框中的图标)
问题描述
在 IE10 中,文本框中会出现一个小 X 图标以清除输入文本.如何将事件附加到该操作(=单击该 X 并清除输入)?
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)?
推荐答案
这似乎没有确切的事件(onchange
不合适).但是,您可以使用 oninput
并检查 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);
如果用户使用 BACKSPACE 或 DELETE 清除 input
或将内容剪切到剪贴板,也会触发此事件.oninput
至少在 Chrome、FF、IE10 和 Opera 中有效.
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 文本框中的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:附加事件以清除 IE10 文本框中的图标


基础教程推荐
- 直接将值设置为滑块 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01